【问题标题】:The requested resource is not available in Struts 2请求的资源在 Struts 2 中不可用
【发布时间】:2014-06-09 03:38:03
【问题描述】:

我在 Tomcat 上运行我的 Struts 应用程序时遇到 The requested resource is not available 错误。

我的目录结构是:

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <!-- remove these constant elements in production -->
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />
    <package name="app02a" namespace="" extends="struts-default">
        <action name="Product_input">
            <result>/jsp/Product.jsp</result>
        </action>
        <action name="Product_save" class="app02a.Product" method="execute">
            <result>/jsp/Details.jsp</result>
        </action>
    </package>

</struts>

Web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5"> 

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Restrict direct access to JSPs. 
         For the security constraint to work, the auth-constraint
         and login-config elements must be present -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>JSPs</web-resource-name>
            <url-pattern>/jsp/*</url-pattern>
        </web-resource-collection>
        <auth-constraint/>
    </security-constraint>

    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>
</web-app> 

注意:

1.我已将所有 jars 包含在 lib 文件夹中,并且它们位于构建路径中

2.我正在使用 struts-2.3.16.1

3.我正在尝试执行此网址

http://localhost:8080/app02a/Product_input.action

【问题讨论】:

  • 定义“包括所有罐子”;不要让我们猜测你在部署什么。

标签: jsp tomcat struts2 http-status-code-404


【解决方案1】:

package 元素中,将namespace 更改为“/”:

<package name="app02a" namespace="/" extends="struts-default">
...
</package>

【讨论】:

    【解决方案2】:

    上面提到的struts.xml“app02”包根据上面提到的URL有一些错误

    http://localhost:8080/app02a/Product_input.action
    

    而是使用struts默认包,应该像下面提到的那样改变。

    <package name="app02a" namespace="/app02a" extends="struts-default">
      <action name="Product_input">......</action>
      <action name="Product_save" class="app02a.Product" method="execute">....</action>
    </package>
    

    【讨论】:

      【解决方案3】:

      如果你使用的是struts-2.3.16.1,你应该使用

      <filter>
          <filter-name>struts2</filter-name>
          <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      </filter>
      

      请参阅Simple Example 代码下方的注释。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-11
        • 2015-02-05
        • 2014-07-01
        • 2015-05-26
        • 2011-11-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多