【问题标题】:The requested resource is not available on Tomcat请求的资源在 Tomcat 上不可用
【发布时间】:2012-08-29 21:08:52
【问题描述】:

我正在尝试让 Struts 教程正常工作,但是当我尝试在 Tomcat 中运行文件时遇到以下错误。

The requested resource () is not available.

Tomcat 日志输出:

Aug 29, 2012 9:55:37 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\GTK2-Runtime\bin;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;.
Aug 29, 2012 9:55:37 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsExample1' did not find a matching property.
Aug 29, 2012 9:55:37 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Aug 29, 2012 9:55:37 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1367 ms
Aug 29, 2012 9:55:37 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Aug 29, 2012 9:55:37 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
Aug 29, 2012 9:55:38 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Aug 29, 2012 9:55:39 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Aug 29, 2012 9:55:39 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/56  config=null
Aug 29, 2012 9:55:39 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1468 ms

我的web.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>StrutsExample1</display-name>

  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
 </servlet>

  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

struts-config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
          "http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>

    <form-beans>
        <form-bean name="helloWorldForm" type="com.vaannila.form.HelloWorldForm"/>
    </form-beans>

    <global-forwards>
        <forward name="helloWorld" path="/helloWorld.do"/>
    </global-forwards>

    <action-mappings>
        <action path="/helloWorld" type="com.vaannila.action.HelloWorldAction" name="helloWorldForm">
            <forward name="success" path="/helloWorld.jsp" />
        </action>
    </action-mappings>

</struts-config>

我将 Tomcat 作为 Eclipse 的插件运行。

【问题讨论】:

  • 您从哪里得到消息“请求的资源不可用?”当您尝试使用浏览器访问应用程序时?
  • 您是否将日志记录设置为 DEBUG 并在启动时检查日志?几乎可以肯定是配置文件中的某些内容,或者由配置文件触发,例如缺少的类/jar 等。
  • @AlexR 是的,我在尝试在浏览器中查看文件时得到它。
  • &lt;pedantry&gt;您不是“在浏览器中查看文件”,而是请求资源。小问题。&lt;/pedantry&gt;
  • 确保查看在 $TOMCAT_HOME/logs 中找到的所有日志文件,包括 catalina.out 和 localhost*.log。在处理此类问题时,几乎在所有情况下,您都会在日志中找到一些堆栈跟踪或线索。

标签: jsp tomcat resources struts struts-1


【解决方案1】:

servlet 映射是*.do 仅通过扩展映射资源。留言

The requested resource () is not available

显示资源路径为空。请求的资源是 Web 应用程序根目录。

即使您有欢迎文件index.jsp,也可能不会被 Tomacat 加载。它也可能不存在。

如果您使用的是 Struts 框架,则不应直接访问 JSP,而要访问 Struts 操作,您应指定映射到该操作的有效 URL。 IE。 http://localhost:8080/StrutsExample1/helloworld.do

【讨论】:

    【解决方案2】:

    您是否在服务器上运行 .java 文件?如果这样做,您会收到此错误。您只需在服务器上运行 .jsp(或 .html)文件,即使您的 .jsp(或 .html) 文件包含一些 .java 文件的方法。浏览器只能运行 .html(或 .jsp) 文件。

    【讨论】:

      猜你喜欢
      • 2017-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多