请教:路径、代码差不多,登录找不到(404)Login,所以无法进行逻辑处理
jsp文件如下 (action路径这个 如果建的.java是Servlet不用配web.xml,如果是自己继承HttpServlet的要配,所以没web.xml方面的问题):
<form method="post" action="Services/Login">
<table align="center">
<tr>
<td>账号:</td>
<td><input type="text" name="user"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="text" name="pwd"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="登录">
</td>
</tr>
</table>
</form>
doGet()和doGet其实是一样的,所以如下:
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
User u = new User();
String username = request.getParameter("user");
String pwd = request.getParameter("pwd");
u.setUsername(username);
u.setPassword(pwd);
System.out.println(u);//作为一个测试,单独run这个.java文件会输出,说明找到了,奇怪的是.jsp跳转就找不到
if (u.getUsername().equals("admin") && u.getPassword().equals("admin")) {
response.sendRedirect(request.getContextPath() + "/show.jsp");
} else {
response.sendRedirect(request.getContextPath() + "/login.jsp");
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}