Servlet3.1下的jsp访问servlet路径错误
程序员文章站
2022-04-17 08:13:35
...
注册的jsp访问TeacherLogonSerlvet的时候显示路径错误
//@WebServlet("/TeacherLogonServlet")
public class TeacherLogonServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String id = request.getParameter("uid");
String pwd = request.getParameter("upwd");
teacherLogin login = new teacherLogin(id,pwd);
ITeacherService teacherService = new TeacherServiceImpl();
boolean rs = teacherService.addTeacherLogin(login);
if(!rs) {
request.setAttribute("addError", "isError");
request.getRequestDispatcher("logon.jsp").forward(request, response);
}else {
request.setAttribute("addError", "noError");
request.getRequestDispatcher("logonSuccess.jsp").forward(request, response);
}
}
因为在Serlvet3.1下,我们需要在类的顶端配置web信息,否则jsp找不到servlet路径
```go
@WebServlet("/TeacherLogonServlet")
public class TeacherLogonServlet extends HttpServlet {
另外我复制了登陆的web配置信息进来,导致了tomcat启动失败,原因是路径重复了,两个serlvet都是登陆servlet的路径。还是萌新,经常犯这种低级错误,效率还是有点低。所以准备记录博客,最少让犯的错误不要重复。