1.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/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>com.hang.servlet.HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>hello</servlet-name>
        <url-pattern>/hello</url-pattern>
    </servlet-mapping>
</web-app>

这里的servlet的name和class以及servlet-mapping的中间内容一定要写对,不然会出错,两个servlet-name是一致的。

2.web文件位置:

这里的index.jsp一定要在web目录下,而不是WEB-INF中。

3.tomcat配置:

 

4.如果以上操作还是没用,那有可能你的web没有添加,可以查看web文件:

 如果你没有,可以按快捷键alt+control+shift+s去设置:

 

 

 

 完成上面的操作即可解决404问题

5.这里我再贴出我的项目路径,你们可以对照去修改:

希望你的问题可以得到解决呀! 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐