Jsp login with messages from servlet and a valid url -


I have to create a login form that displays an error message (such as "incorrect user / password - try again") .

LoginHandler.java:

@WebServlet ("/ login") Public Category LoginHandler HttpServlet Extended {@ Override Secure Zero DoPost (HttpServletRequest Request) , HttpServletResponse response) {// ... if (userInvalid ()) {request.setAttribute ("error", "wrong user / password - retry"); Request (request / response); }} // <}>

index.jsp:

  & lt; P & gt; & Lt;% out.println (request.getAttribute ("Error")); % & Gt; & Lt; / P & gt; & Lt; Form action = "/ login" method = "post" encrypt = "application / x-www-form-urxcode" & gt; ...  

Everything is fine, but I am using the URL http: // & lt; Server>: 8080 / login I found after request.getRequestDispatcher ("/ index.jsp"). Forwarded (request, response); sends the request. This is not a URL that can be entered in my set up in the browser.

Is there any way you can send index.jsp whitout using the session variable, and with the URL like this, http: // : 8080 / index.jsp?

If I understand your problem properly, then you get the servlet address in the browser if you Do you navigate to this address then you get an error? If so, you can "redispatch" in doGet-method:

  Public Zero doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.getRequestDispatcher ("/ index Jsp "). Forward (request, response); }  

In this case, the servlet should be sent to jsp.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -