资源在Struts 2中不可用 [英] Resource not available in Struts 2
问题描述
我是Struts的新手,我想执行HelloWorld程序,但是一旦在web.xml
中写入<filter>
标记,就会收到请求的资源不可用"错误.
I am new to Struts and I want to execute HelloWorld program, but I am getting "Requested resource not available" error as soon as I write a <filter>
tag in web.xml
.
web.xml
:
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>Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>
struts.xml
:
struts.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="helloworld" extends="struts-default">
<action name="hello" class="sagar.practice.HelloWorldAction" method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
我将所有必需的struts jar添加为用户库.
I added all required struts jars as a user library.
我正在以http://localhost:8080/practice/index.jsp
如果我从web.xml
文件中删除<filter>
标记,则可以访问index.jsp
页面,但是如果添加<filter>
标记,则会出现请求的资源不可用"错误.
If I remove <filter>
tag from web.xml
file I am able access index.jsp
page, but if I add <filter>
tag it is giving "Requested resource not available" error.
推荐答案
您应通过在struts.xml
中设置常量来打开devMode
.如果您想解决像您这样的问题,可以使用此模式.它提供了更多信息,因为它会将正常模式下隐藏的错误输出到控制台.
You should turn on devMode
on via setting a constant in the struts.xml
. This mode is used if you want to troubleshot some issues like yours. It's more informative because it outputs to the console errors that are hidden in the normal mode.
<constant name="struts.devMode" value="true" />
打开它后,您可能会发现您的应用程序部署的库集有误或不一致.您可能会发现java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
打印到控制台,然后使用缺少的jar来调整库集.
After turning it on you may discover that you have wrong or inconsistent library set deployed with your application. You might find a java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
printed to the console, then adjust your library set with missing jars.
commons-lang3-3.1.jar
是解决错误所必需的.
The commons-lang3-3.1.jar
is required to resolve error.
这篇关于资源在Struts 2中不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!