java - Parameters passed to URL not working -


when input values form, going through if-else accordingly.

however, when pass parameters via url this:

http://localhost:8080/sessiondemo/index.html?user=wronguser&pass=wrongpass

it not going through anything. none of println's executing (not user/pass/end). goes form.

may know why so?

<form action = "processlogin.cgi" method = "post">     <p>username: <input type = "text" name = "user" size = "25"/></p>     <p>password: <input type = "password" name = "pass" size = "25"/></p>     <input type = "submit" value = "login"/> </form>    @webservlet("/processlogin.cgi") public class processloginservlet extends httpservlet {     private static final long serialversionuid = 1l;      protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {         dopost(request, response);     }      protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {         string user = request.getparameter("user");         string pass = request.getparameter("pass");          system.out.println("user: " + user);         system.out.println("pass: " + pass);          if(usermanager.isvaliduser(user, pass)) {             system.out.println("valid");          } else {             system.out.println("invalid")         }          system.out.println("end");     } } 

your servlet handles post requests.

when enter url

http://localhost:8080/sessiondemo/index.html?user=wronguser&pass=wrongpass 

or set method in html form generating request.

to handle requests need override httpservlet.doget or httpservlet-service.

the code using in dopost method works fine requests.

update:

your servlet registered path /processlogin.cgi therefore test call browsers need enter

http://localhost:8080/sessiondemo/processlogin.cgi?user=wronguser&pass=wrongpass 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -