JSP servlet does not execute the doPost method

advertisements

I have recently started programming in java and have been trying out some JSP development. I am trying to make a login page which uses the POST method to transfer data to the servlet. Here is my code:

<form method="POST" name ="loginForm"  action="userAuth">
            <input type="hidden" name="userAction" value="login">
            Username: <input type="text" name="txtUsername"> <br>
            Password    : <input type="password" name="txtPassword">
            <br><input type="submit"  value="Login">

</form>

The above code is from the initial login page.

The code below is from the userAuth.java file.

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
    String userAction = request.getParameter("userAction");
    if (userAction.equals("Login")) {
    String userName = request.getParameter("txtUsername");
    String passWord = request.getParameter("txtPassword");

    if (userName.equals("hello") && passWord.equals("hello")) {
    response.sendRedirect("Homepage.jsp");
    }
    }
}

The problem I have is that when I input the correct username and password, the doPost method is not executed, so none of the redirects take place. Rather only the ProcessRequest method is executed which just displays the initial template to the web browser.

Thank you in advance.

P.S I am using Apache Tomcat 8.0.27.0


I have solved the issue...

The issue was with the following line

<input type="hidden" name="userAction" value="**login**">

and the subsequent processing in the second block:

if (userAction.equals("**Login**")) {}

The login value didnt have an uppercase L.

Just changed this.