Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

java - Resource not available in Struts 2

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.

Project hierarchy

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 :

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

I added all required struts jars as a user library.

I am accessing index page as : http://localhost:8080/practice/index.jsp

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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" />  

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.

The commons-lang3-3.1.jar is required to resolve error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...