系统找不到这个对应的 URL 映射,所以会返回 404 错误
1.@WebServlet注解:确保 /UserServlet对应的 UserServlet的 @WebServlet注解
@WebServlet(name = "UserServlet",urlPatterns = "/UserServlet")
public class UserServlet extends HttpServlet {
//声明IUserService对象
private IUserService userService = new UserServiceImpl();
2.检查路径映射: 确保 @WebServlet(urlPatterns = "/UserServlet")
中的 urlPatterns
与你在重定向中使用的路径一致。如果你的项目有上下文路径,例如 /myproject03_war_exploded
,需要将它包含在重定向的路径中。
例如,如果 /UserServlet
是相对于上下文路径的,在user.jsp中為
<a href="/myproject03_war_exploded/UserServlet" target="rightFrame">
重定向应该是:
resp.sendRedirect("/myproject03_war_exploded/UserServlet");
如果沒用的話試試重啓idea,it will be help