本文写给初学者,也写给自己以后需要重新部署项目时作为参考,如果正好帮助了您,请您反馈给我,增加我在成长过程中不断分享的动力。
网上关于tomcat安装及环境变量设置的过程已经很多,我再此不再赘述。
问题:tomcat在测试是否安装成功时可以成功访问localhost:8080。但是在eclipse中tomcat已经设置好的情况下,部署项目时出现404页面。
笔者做了以下两点主要的动作【已解决此问题】:
1、很多教程(书本、视频)引导大家必须要在web.xml中配置对应的参数,
我装的tomcat是8.0.23的
jdk和jre环境都是1.8.0的
是不能去手动配置web.xml的
猜想可能是最新的tomcat与eclipse已经不再需要我们去做这步工作,添加后反而画蛇添足。
我的web.xml文件代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>FirstWeb</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
2、以上设置完成,在eclipse中部署后,依然显示404错误。
度了很久无果,可能是造成404错误的原因实在太多吧!
1)经过多次尝试偶然发现,在部署前,删除当前的项目(见下图)。
2)并停止tomcat的运行(右键--stop)。
3)仅打开目前我们编辑的servlet文件(感觉这里就是问题的大症结,因为我上几次每次都打开在web.xml文件里),点运行就好了。
我的已经部署出来了,赶紧试试这个方法吧!