0

I've a login page where in I take the details of the user.

login.jsp

<form action="loginPage" method="post">
<table style="width: 30%">
    <tr>
        <th>user :</th>
        <td align="center"><input type="text" name="uid" id="uid"></td>
    </tr>
    <tr>
        <th>Password :</th>
        <td align="center"><input type="text" name="password"
            id="password"></td>
    </tr>
    <tr>
        <td align="center" colspan="2"><input type="submit"
            value="Submit"></td>
    </tr>


</table>
</form>

login.java

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        response.setContentType("text/html");  
        PrintWriter out = response.getWriter();  

        String n=request.getParameter("uid");  
        String p=request.getParameter("password"); 
        System.out.println("here");

        ......  
     out.close();

  }

web.xml

 <servlet>
 <servlet-name>Page</servlet-name>
 <servlet-class>com.ui.login.login</servlet-class>
 </servlet>

 <servlet-mapping>
 <servlet-name>Page</servlet-name> 
 <url-pattern>/loginPage</url-pattern>
 </servlet-mapping>

the problem is when I click on the submit button I get an error saying,

>>The requested resource is not available.
Sam
  • 513
  • 1
  • 11
  • 27

3 Answers3

1

You should write something to the response.

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        response.setContentType("text/html");  
        PrintWriter out = response.getWriter();  

        String n=request.getParameter("uid");  
        String p=request.getParameter("password"); 
        out.write("here");
        out.flush();
  }
  • Thanks for the reply. I edited the code as you said. Still same error. The action is not hitting my java class file. – Sam Sep 05 '15 at 11:00
  • The servlet is mapped to the `/loginPage` but action is not mapped to the servlet, this causes 404 error, or servlet is just in the worse case didn't start. –  Sep 05 '15 at 14:27
1

Please check the your project directory structure and your URL, enter image description here

enter image description here

SaviNuclear
  • 886
  • 1
  • 7
  • 19
-1

Your form action and URL pattern in web.xml should match. / is missing in action attribute of your form tag.

Rahul Yadav
  • 1,503
  • 8
  • 11
  • `/` in `action` doesn't represents root of project, but root of server. So `action='/loginPage'` will represent `server/loginPage` instead of `server/project/loginPage`. – Pshemo Sep 05 '15 at 10:45