Here is piece from my HTML code:
<form action="LoginServlet" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password">
<input type="submit" value="Log In">
</form>
and here is servletContextListener:
public class DataListener implements ServletContextListener {
private AccountManager accs;
ServletContext context;
/**
* Default constructor.
*/
public DataListener() {
// TODO Auto-generated constructor stub
}
/**
* @see ServletContextListener#contextInitialized(ServletContextEvent)
*/
public void contextInitialized(ServletContextEvent e) {
accs = new AccountManager();
context = e.getServletContext();
context.setAttribute("accounts", accs);
}
/**
* @see ServletContextListener#contextDestroyed(ServletContextEvent)
*/
public void contextDestroyed(ServletContextEvent e) {
context = e.getServletContext();
}
}
and here is my servlet doPost :
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//ServletContext context = getServletContext();
//AccountManager manager = (AccountManager) context.getAttribute("accounts");
/*if (manager.isValid(request.getParameter("username"),request.getParameter("password"))){
RequestDispatcher dispatch = request.getRequestDispatcher("welcome.jsp");
dispatch.forward(request, response);
} else{ */
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>");
out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\""
+ " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
out.println("<html xmlns='http://www.w3.org/1999/xhtml'>");
out.println("<head>");
out.println("<title>Information Incorrect</title>");
out.println("</head>");
out.println("<body>");
out.print("<h1>Please Try Again </h1>");
out.print("<br />");
out.print("Either Your username or password is incorrect. Please try again.");
out.print("<br />");
out.print("<br />");
request.getRequestDispatcher("/LoginForm.html").include(request, response);
out.println("</body>");
out.println("</html>");
// }
Problem is that, when i run welcome.html and push login button, still old code does its work. I'mean i've commented this part:
/*if (manager.isValid(request.getParameter("username"),request.getParameter("password"))){
RequestDispatcher dispatch = request.getRequestDispatcher("welcome.jsp");
dispatch.forward(request, response);
} else{ */
but still, when i push button, this, commented block executes...
so i can't change anything there.. anybody can explain how can i restart my servlet class? or what's the problem?
thank you in advace
i did Project->clean and it worked :)