package com.cv.jsp.scopes;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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);
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public TestServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
LOGGER.info("Entered into doGet(HttpServletRequest ,HttpServletResponse ) of TestServlet class... ");
response.setContentType("text/html");
String userName = request.getParameter("userName");
String city = request.getParameter("city");
String gender = request.getParameter("gender");
LOGGER.info("You have entered the username as : " + userName);
LOGGER.info("You have entered the city as : " + city);
LOGGER.info("You have entered the gender as : " + gender);
if (userName != null && userName.length() > 1) {
request.getSession().setAttribute("userName", userName);
getServletContext().setAttribute("city", city);
request.setAttribute("gender", gender);
RequestDispatcher dispatcher = request.getRequestDispatcher("jspscopes.jsp");
dispatcher.forward(request, response);
} else {
LOGGER.info("You have entered INVALID username. PLEASE enter username as : chandra ");
RequestDispatcher dispatcher = request.getRequestDispatcher("start.html");
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(HttpServletRequest ,HttpServletResponse ) of TestServlet class... ");
doGet(request, response);
}
} |
No comments:
Post a Comment