且构网

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

HTTP 状态 404 - 请求的资源不可用

更新时间:2022-10-19 15:57:55

我认为没有任何理由在您的类路径中添加 javax.servlet-3.0.1.jar.正在使用 Eclipse 来构建/运行您的应用程序,因此当您将 tomcat 或任何服务器作为运行时环境添加到您的项目时,这些 lib 依赖项将自动添加到类路径中.简单地从您的项目的 lib 文件夹中删除此 jar.这也可能有其他原因.

  1. javax.servlet-3.0.1.jar 已添加为运行时库(在 .WAR 中)——并且仅在构建时需要它.
  2. 从 WEB-INF/lib 中删除 jar,并更新您的构建脚本以指向新位置.

引用的 Servlet 规范 2.3,第 9.7.2 节说 Servlet 容器(例如 Tomcat)将提供 J2EE 规范的实现类.WEB-INF/lib 目录中的 j2ee.jar(在我们的例子中是 servlet-api.jar?)试图提供相同的信息.具有特定于应用程序的实现是一个稳定性和安全性问题,这是规范 2.3 和 Tomcat 不允许的.

简而言之,从您的 lib 文件夹中删除 javax.servlet-3.0.1.jar,让容器负责为您提供这些依赖项.

要声明由容器提供的依赖项,maven 将范围设置为提供",这里是 pom.xml 中条目的外观示例:

 <groupId>javax</groupId><artifactId>javaee-web-api</artifactId><version>6.0</version><范围>提供</范围></依赖>

I'm running into a recurring problem while using the Tomcat server within the MyEclipse IDE, with the Struts 2 framework. I'm running my program as a server application and when it runs the default index.jsp file will open successfully but none of the other pasts of the application will work. When trying to load any of my my .do pages, I get the following error: HTTP Status 404: The requested resource .... is not available. When I ran into this error previously, I just restarted the server and all was fine, but I'm not having the same luck now.

Here's the log from the console when I hit run.

Apr 12, 2012 10:49:35 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin;C:\Program Files\MyEclipse\Common\plugins\com.genuitec.eclipse.easie.tomcat.myeclipse_9.0.0.me201109141806\tomcat\bin
Apr 12, 2012 10:49:35 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Apr 12, 2012 10:49:35 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 285 ms
Apr 12, 2012 10:49:35 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Apr 12, 2012 10:49:35 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.13
Apr 12, 2012 10:49:35 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Documents and Settings\username\My Documents\Workspaces\.metadata\.me_tcat\webapps\project-name\WEB-INF\lib\javax.servlet-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
log4j:WARN No appenders could be found for logger (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider).
log4j:WARN Please initialize the log4j system properly.
Apr 12, 2012 10:49:37 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Apr 12, 2012 10:49:37 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Apr 12, 2012 10:49:37 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/16  config=null
Apr 12, 2012 10:49:37 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1720 ms

Any suggestions?

I don't see any reason to add javax.servlet-3.0.1.jar in your class-path.Since you are using Eclipse to build/run your application, so when you will add tomcat or any server as run time env to your project these lib dependencies will automatically be added to the class-path.Simple remove this jar from the lib folder of your project. There can be other reasons also for this.

  1. javax.servlet-3.0.1.jar has been added as runtime library (in the .WAR) – and that it was only needed during build time.
  2. Remove the jar from WEB-INF/lib, and update your build script to point to the new location.

the Servlet Spec 2.3, section 9.7.2 being referred to says that the Servlet Container (E.g. Tomcat) will supply the implementation class of the J2EE spec. The j2ee.jar (servlet-api.jar in our case?) in your WEB-INF/lib directory is trying to supply the same info. Having application specific implementations is a stability and security problem that is disallowed by the spec 2.3 and by Tomcat.

In short remove the javax.servlet-3.0.1.jar from your lib folder and let the container take care of supplying these dependencies for you.

To declare a dependency which is provided by the container with maven set the scope to "provided" here is an example of how an entry in your pom.xml should look:

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>