且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误404,未在Tomcat中找到Servlet

更新时间:2023-08-21 19:44:34

我意识到这是一个旧线程,但是我一直在努力解决一个非常相似的问题,并找到了解决方案.我以为我会分享...

I realize that this is kind of an old thread, but I've been struggling with a very similar problem and just found the solution to it. I thought I'd share...

我对Maven还是比较陌生,并且一直在使用maven 3.1,tomcat 7.0.37,java 1.7和Eclipse Juno来解决一个非常类似的问题.我将使用maven-archetype-webapp创建一个maven项目,然后使用动态Web模块将该项目转换为多面形式,并将内容目录设置为/src/main/webapp.

I am relatively new to Maven and have been struggling with a very similar problem using maven 3.1, tomcat 7.0.37, java 1.7, and Eclipse Juno. I would create a maven project using maven-archetype-webapp, and then convert the project to faceted form using the Dynamic Web Module, setting my content directory to /src/main/webapp.

我将创建我的servlet类,并确保将servlet-api.jar包含到Java构建路径中.我还更新了pom.xml,使其具有对javax.servlet-api的依赖关系,范围为提供":

I would create my servlet class and make sure to include servlet-api.jar to the java build path. I also updated my pom.xml with a dependency to javax.servlet-api with a scope of 'provided':

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1-b05</version>
    <scope>provided</scope>
</dependency>

我将项目包含在tomcat服务器中,当访问servlet URL时,会出现404错误-请求的资源不可用.

I included the project to the tomcat server, and when visiting the servlet url, I would get a 404 error - The requested resource is not available.

我为此苦苦挣扎了两天,直到今天早上才找到解决方案.我缺少的部分是进行"Maven安装".由于我使用的是Eclipse,因此需要右键单击项目,选择运行方式",然后选择"Maven安装".之后,我停止/重新启动了本地tomcat服务器,然后我就能够成功地使servlet正常工作.

I struggled with this for like two days and just this morning discovered the solution. The part that I was missing was to do a 'maven install'. Since I'm using Eclipse, that involved right clicking on the project, selecting 'Run As', and then 'Maven Install'. After that, I stopped/restarted my local tomcat server, and I was then able to successfully get the servlet to work.

我注意到的另一件事是,当查看java构建路径中的库选项卡时,开箱即用配置的JRE系统库是J2SE-1.5.我将其更改为JavaSE-1.7(jdk1.7.0_13).

Something else that I noticed is that when looking at the libraries tab in the java build path, the JRE system library that was configured out of the box was J2SE-1.5. I changed mine to JavaSE-1.7 (jdk1.7.0_13).

最终使我对这个问题最有帮助的是该视频:

What ended up helping me the most on this problem was this video:

http://www.***.com/watch?v=8Waf4jBbino

我希望这对某人有帮助!

I hope this helps someone!