请求的资源不可用。 (jsp,servlet)

时间:2015-09-05 10:36:07

标签: java jsp servlets

我是一个登录页面,我在其中详细介绍了用户。

的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 requested resource is not available.

3 个答案:

答案 0 :(得分:1)

你应该在回复中写点什么。

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();
  }

答案 1 :(得分:1)

请检查项目目录结构和URL, enter image description here

enter image description here

答案 2 :(得分:-1)

您在web.xml中的表单操作和网址格式应该匹配。 /表单标记的action属性中缺少/。