资源在 Struts 2 中不可用 [英] Resource not available in Struts 2

查看:40
本文介绍了资源在 Struts 2 中不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Struts 新手,我想执行 HelloWorld 程序,但在 web 中编写 <filter> 标记后,我立即收到请求的资源不可用"错误.xml.

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:

    <?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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆