package com.cv.servlet.filter.param;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
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 LoginServlet
*
* @author Chandra Vardhan
*
*/
public class LoginServlet extends HttpServlet {
private final String userID = "ardnahc";
private static final Logger LOGGER = Logger.getLogger(LoginServlet.class);
/**
* Constructor of the object.
*/
public LoginServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
LOGGER.info("Entered into doGet(HttpServletRequest ,HttpServletResponse ) of LoginServlet class... ");
String user = request.getParameter("dangerousParamName");
LOGGER.info("dangerousParamName parameter value is : " + user);
if (userID.equals(user)) {
HttpSession session = request.getSession();
LOGGER.info("dangerousParamName attribute value setting is : "
+ user);
LOGGER.info("dangerousParamName value is changed by filter : "
+ user);
session.setAttribute("dangerousParamName", user);
LOGGER.info("sendRedirecting to success.jsp...");
response.sendRedirect("success.jsp");
} else {
RequestDispatcher rd = getServletContext().getRequestDispatcher(
"/login.html");
PrintWriter out = response.getWriter();
out.println("<font color=red>user name is wrong. Please look at logs... </font>");
LOGGER.info("Enter username = 'chandra' ");
rd.include(request, response);
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
LOGGER.info("Entered into doPost(HttpServletRequest ,HttpServletResponse ) of LoginServlet class... ");
doGet(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
} |
No comments:
Post a Comment