Saturday, 15 January 2011

java - HTML form for login always returns null values in request parameters -



java - HTML form for login always returns null values in request parameters -

i don't know why stuck in simple, cant out of it.

first html file using

<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>welcome guest- please login</title> <script type="text/javascript"> function validate() { username = document.getelementbyid("username").value; password = document.getelementbyid("password").value; if( username==null || username=="" ) { alert("please come in username"); homecoming false; } if( password==null || password=="" ) { alert("please come in password"); homecoming false; } homecoming true; } </script> </head> <body> <form action="login" method="post"> <br /> name: <input type="text" name="username" id="username" /> <br /> password: <input type="password" name="password" id="password" /> <br /> <input type="submit" onclick="return validate()" /> </form> </body> </html>

and dopost() method of servlet

protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { userlogindaoimplementation usr = new userlogindaoimplementation(); string username = request.getparameter("username"); string password = request.getparameter("password"); system.out.println(username + password); user u = usr.getpassword(username); if( u.getpassword().equals(password)) { // if password matches response.sendredirect("images"); } else { response.sendredirect("invalid"); } }

i have searched net kinds of queries nil works. know there problem of enctype , , have tried along numerous other experiments. every time run this, print statements print nullnull , null pointer exception thrown. really stuck this. please tell me wrong.

i using eclipse juno tomcat , other java ee plugins.

edit:

just suspected, problem somewhere else entirely. run programme today without touching previous code , worked charm. dont know hell wrong yesterday. new eclipse , noticing such behavior eclipse 1 time again , 1 time again since started using tomcat. had restart eclipse create render changes made in html files love have work around. restarted eclipse several times problem not working @ all. so can please guide me tips remembered while working web applications in eclipse...

java servlets

No comments:

Post a Comment