
idea的run------>> edit configurations--------->>Deployment修改Tomcat的Appication Context,加上项目名称,可以解决报404错误,解决路径访问的问题。
开始找了很久,也没发现哪里错误,反复修改web.xml也是没用,以为自己写的路径有问题,访问页面试了很多遍,有时真是费时间。
附上学习过程简单的代码:
**servlet代码:**
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 4023442997406361930L;
public HelloServlet(){
super();
}
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException {
PrintWriter out =res.getWriter();
out.println("HelloServlet");
out.close();
}
}
**web.xml简单的配置**
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xm

在使用IDEA学习Servlet时遇到404错误,但JSP页面能正常访问。通过编辑Run配置,修改Tomcat的Application Context添加项目名,可以解决路径问题。此方法避免了对web.xml的反复修改和路径错误的困扰。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



