2014-04-24 35 views
0

我是struts的新手。我有在tomcat上运行我的Struts应用程序时,请求的资源不可用错误。Struts2请求的资源不可用

我的目录结构是:

enter image description here

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.I已包括在lib文件夹和所有罐子他们在构建路径

2.I使用的struts-2.3.16.1

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

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

请帮助我所缺少的

+0

定义“included all jars”;不要让我们猜你正在部署什么。 –

回答

0

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

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

如果您正在使用的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

0

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

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>