【发布时间】:2015-05-05 20:15:03
【问题描述】:
我有简单的login.jsp 页面:
<form class="form-horizontal" role="form" action="/SchoolERP/Login" method="post">
<div class="form-group">
<label for="username" class="control-label col-sm-1">Username:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="username" placeholder="Username">
</div>
</div>
<div class="form-group">
<label for="password" class="control-label col-sm-1">Password:</label>
<div class="col-sm-5">
<input type="password" class="form-control" id="password" placeholder="Password">
</div>
</div>
<div class="col-sm-offset-1 col-sm-5">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</form>
我的web.xml 文件包含以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SchoolERP</display-name>
<servlet>
<servlet-name>SchoolERP</servlet-name>
<servlet-class>com.rms.school.controllers.ControllerHome</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SchoolERP</servlet-name>
<url-pattern>/SchoolERP</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>com.rms.school.controllers.ControllerLogin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/SchoolERP/Login</url-pattern>
</servlet-mapping>
<welcome-file-list>
<!-- This welcome filename is linked to above mentioned url-pattern -->
<welcome-file>SchoolERP</welcome-file>
</welcome-file-list>
</web-app>
其中ControllerLogin.java如下:
public class ControllerLogin extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher rd = request.getRequestDispatcher("jsp/template.jsp");
request.setAttribute("content_page", "admin/login.jsp");
request.setAttribute("title", "Login");
rd.forward(request, response);
}
}
当我单击 Login.jsp 页面上的提交按钮时,它给出的错误为requested resource /SchoolERP/Login not found。我哪里做错了?
我在 login.jsp 中尝试了各种变体,例如 action="Login"。同样在web.xml 中,我尝试使用Login、/SchoolERP/Login 等。但仍然存在错误。
【问题讨论】: