无法从jsp文件发布到servlet

时间:2015-03-11 02:27:56

标签: java jsp servlets

我有一张表格

<form method="POST" action="${pageContext.request.contextPath}/validate">
        Username: <input type="text" name="username" id="username"/><br />
        Password: <input type="password" name="password" id="password"/><br />
        <input type="submit" value="Submit"  id="btnSubmit"/>&nbsp;
        <input type="reset" value="Clear" id="btnClear"/>
</form>

预计会发布到validate.java servlet

的web.xml

<web-app>
<servlet>
    <servlet-name>validate</servlet-name>
    <servlet-class>springapp.validate</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>validate</servlet-name>
    <url-pattern>/validate</url-pattern>
  </servlet-mapping>
</web-app>

文件夹结构

enter image description here

validate.java包含一个简单的重定向

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter out = response.getWriter();
        response.setContentType("text/html");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if(username.equals("admin") && password.equals("pass")){
            response.sendRedirect("Main.jsp");
        }
        else{
            response.sendRedirect("index.jsp");
        }
    }

0 个答案:

没有答案