下面是代码,本人没有动那个web.xml
package controller; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import domain.User; import service.UserService; public class LoginServlet extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String username = req.getParameter("username"); String userpsw = req.getParameter("userpsw"); User user = new User(); user.setUsername(username); user.setUserpsw(userpsw); HttpSession session = req.getSession(); String forward = ""; if (UserService.CheckLogin(user)) { forward = "success.jsp"; session.setAttribute("name", username); } else { forward = "error.jsp"; } RequestDispatcher rd = req.getRequestDispatcher(forward); rd.forward(req, resp); } }
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%> <html> <head> <title>login</title> </head> <body> <form action="login" method="post"> 用户名称:<input type="text" name="username" value=""><br> 用户密码:<input type="password" name="userpsw" value=""><br> <input type="submit" name="submit" value="登陆"> <input type="reset" name="reset" value="重写"> </form> </body> </html>
解决方案
10
404很明显,跳转的路径不存在
5
你就写个success.jsp,也不写个路径,他没找到。给齐纳买加上路径就行了
5
浏览器中URL地址写错了,或web.xml中action没有和form表单中的action对应上。
反正404肯定过是路径问题
反正404肯定过是路径问题
5
你看看你要跳转的路径,你再看看你404界面浏览器的地址
20
<filter> <filter-name>Servlet</filter-name> <filter-class>你的包名加类名</filter-class> </filter> <filter-mapping> <filter-name>Servlet</filter-name> <url-pattern>/</url-pattern> </filter-mapping>
加到里边