Question

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 :)

Was it helpful?

Solution

Giorgi, this should be easily addressed by Build > Clean. If it continues to be stubborn, take note that in Eclipse, the generated classes are written into the directory specified in the Java Build Path utility:

enter image description here

You can manually delete the class files created here. The directory will be hidden in Eclipse package explorer though. Instead of changing the default Eclipse view filters, you can do it directly in the file system.

Then rebuild. It should fix your problem.

OTHER TIPS

Your application may be cached under the tomcat directory tomcat\work\Catalina\localhost. Try deleting your application from this directory and redeploy your application or simple restart tomcat.

If above does not help then there is surely some glitch with the eclipse WAR creation or deployment.Build your WAR, and make sure it contains the updated class files. The key is, to check the file dates in the Tomcat directory of where you deployed the WAR. It may happen even though you are deploying an entirely new cleaned WAR, and deleting all folders, there were still older cached files in there, probably because Eclipse keeps them to save compile time, thinking they don't have any changes. Make sure the war or webapp folder in your Tomcat contains the latest class files and then you should be good.

Good Luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top