html5 - How to display an error message from servlet? -


i want display error message when login , password wrong, tried attempt didnt't work, thanks.

index.html

<body> <form action="serv"> <input type="text" name="log"> <input type="password" name="pwd"> <input type="submit" value="send"> </form> </body> 

serv.java

 response.setcontenttype("text/html;charset=utf-8");  printwriter out = response.getwriter();   string u =request.getparameter("log");  string p =request.getparameter("pwd");  if(u != "admin"  && p!= "admin"){  string somemessage = "error !";  getservletcontext().getrequestdispatcher("/index.html").forward(request, response);   out.println("<html><head>");  out.println("<script type=\"text/javascript");    out.println("alert("+ somemessage +");</script>"); out.println("</head><body></body></html>"); } 

use single quotes inside when possible, try this:

string somemessage = "error !"; out.println("<script type='text/javascript'>"); out.println("alert(" + "'" + somemessage + "'" + ");</script>"); out.println("</head><body></body></html>"); 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -