java - When I change servlet content in doPost, nothing happens -
here piece 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 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 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 username or password incorrect. please try again."); out.print("<br />"); out.print("<br />"); request.getrequestdispatcher("/loginform.html").include(request, response); out.println("</body>"); out.println("</html>"); // }
problem that, when run welcome.html , push login button, still old code work. i'mean i've commented part:
/*if (manager.isvalid(request.getparameter("username"),request.getparameter("password"))){ requestdispatcher dispatch = request.getrequestdispatcher("welcome.jsp"); dispatch.forward(request, response); } else{ */
but still, when push button, this, commented block executes... can't change there.. can explain how can restart servlet class? or what's problem? thank in advace
i did project->clean , worked :)
giorgi, should addressed build > clean. if continues stubborn, take note in eclipse, generated classes written directory specified in java build path utility:
you can manually delete class files created here. directory hidden in eclipse package explorer though. instead of changing default eclipse view filters, can directly in file system.
then rebuild. should fix problem.
Comments
Post a Comment