這是從我的HTML代碼塊:當我的doPost改變servlet的內容,沒有任何反應
<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>
這裏是的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();
}
}
,這裏是我的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>");
// }
Probl時間就是這樣,當我運行welcome.html並按下登錄按鈕時,仍舊舊的代碼執行其工作。 I'mean我已經評論說這部分:
/*if (manager.isValid(request.getParameter("username"),request.getParameter("password"))){
RequestDispatcher dispatch = request.getRequestDispatcher("welcome.jsp");
dispatch.forward(request, response);
} else{ */
但儘管如此,當我按下按鈕,這個評論塊執行... ,所以我不能有任何改變..任何人都可以解釋我如何能重新啓動我的servlet類?或者是什麼問題? 謝謝你在advace
我所做的項目 - >乾淨,它的工作:)
我正在Eclipse Juno和Tomcat 7.0上工作 – 2013-05-04 12:48:15