package com.cv.jsp.el.scope;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
/**
* Servlet implementation class MyServlet
*
*
* @author Chandra Vardhan
*
*/
public class TestServlet extends HttpServlet {
private static final Logger LOGGER = Logger.getLogger(TestServlet.class);
/**
* @see HttpServlet#HttpServlet()
*/
public TestServlet() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
LOGGER.info("Entered into doGet(--) of TestServlet class... ");
HttpSession session = request.getSession();
response.setContentType("text/html");
String name = request.getParameter("name");
Person person = new Person();
person.setName(name);
Person person2 = new Person();
person2.setName(name + " session");
request.setAttribute("person", person);
request.setAttribute("foo.person", person);
// person.setName(name + "vardhan");
session.setAttribute("person", person2);
session.setAttribute("foo.person", person2);
Person person3 = new Person();
person3.setName(name + " context");
ServletContext context = getServletContext();
context.setAttribute("person", person3);
context.setAttribute("foo.person", person3);
RequestDispatcher dispatcher = request
.getRequestDispatcher("result.jsp");
dispatcher.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
LOGGER.info("Entered into doPost(--) of TestServlet class... ");
doGet(request, response);
}
} |
No comments:
Post a Comment