Struts2 does not find jsp files

I'm trying to uselessly create a simple Struts2 application so I can continue exploring the structure. Basically, I expect that when an activity is triggered that is not defined, the default page will appear.

This application is being developed in Eclipse.

I have a very simple struts.xml file created in the WEB-INF / classes directory:

<struts>
<!-- Include webwork default (from the Struts JAR). -->
<include file="struts-default.xml" />

<!-- Configuration for the default package. -->

<package name="default" extends="struts-default">
    <action name="*">
        <result>/test.jsp</result>
    </action>
</package>
</struts>

      

I have a test.jsp file (only the default jsp template that is generated in Eclipse ie "Insert header here") at the WebContent level and the welcome page (which triggers the action) is index.jsp also at the same level and is displayed when the program starts. It is defined as follows:

 <%@page contentType="text/html" pageEncoding="UTF-8"%>
 <%@ taglib prefix="s" uri="/struts-tags" %>

<html>
  <head>
    <title>GlassFish JSP Page</title>
  </head>
<body>
<h1>Hello World!</h1>
<s:form action="other">
   <s:submit value="Submit" />
</s:form>
</body>
</html> 

      

I have also tried this with other action names and no matter what, I am returning a 404 page not found. I tried this on both GlassFish and Websphere 6.1.1 with the same results, which made me suspect that there is something I am missing, which is probably right in front of me, including any directory structure (these are the paths regarding spacers .xml file or context root?) or some config file.

After some attempts, I was able to get Eclipse Ganymede up and running on Mac OS X 10.5.6 using Glassfish, but I still had no luck with IBM Websphere and Application Server Toolkit (a derivative of Eclipse) on Windows XP. I'm a bit suspicious that it might have something to do with the browser.

I just tried adding a file called "other.action" in the same directory as my other JSP files mentioned above. Now when I click on the submit button associated with the "other" action, the action continues successfully on my test.jsp page. I may be wrong, but I don't think I need to provide a file called "someaction.action" for every possible "someaction" I might need to use (I know I don't need it in OS X to run my application).

Additional updates - I just tried this on Firefox 3.5.2 and running in that browser gave the same results - no file found without other.action file in Websphere, so now I suspect it's a Websphere configuration issue.

+2


source to share


3 answers


Using Firefox provided the key that I need to determine the source of this problem - Error 404: Post SRVE0190E, which said the problem was related to Websphere configuration.

The problem is explained in more detail at the following link:

IBM Websphere WebContainer throws a FileNotFoundException when it receives a request for a static file that is not on the file system.

And the solution is explained from this link (in this case, setting com.ibm.ws.webcontainer.invokefilterscompatibility = true):

Setting Websphere Custom Properties

For completeness, I'll show you how to fix this problem here:

-In the administrative console click "Servers" and under the servers click "Application Servers"



-Click on the server to which the custom property will apply

-Default "Configuration" and "Container Options" click "Web Container Settings" and in the "Web Container Options" section click "Web Container"

- "Configuration" and "Advanced Properties" click on "Custom Properties"

- On the Custom Properties page, click New

- On the settings page, enter the name of the custom property to be added to the Name field and the value to be set for the custom property in the Value field. Please note that some properties are case sensitive. For this problem the property is "com.ibm.ws.webcontainer.invokefilterscompatibility" and the value will be "true"

-Click "Apply" or "OK"

-Open "Save" in the "Messages" window that appears. Restart the server for the custom property to take effect.

+2


source


You will definitely click the context root for your application. those. to web.xml

app has a name, this is usually the same as the root of the context, unless you packaged your app into a war file with a different name.

http://yourserver:8080/yourcontextroot

      

I believe Stuts 2 comes with some web app examples and some maven archetypes. It's always a good idea to start with one of these and then customize it to your needs.

http://struts.apache.org/2.1.2/docs/struts-maven-archetypes.html

Struts 2 has a sample project named struts-blank-2.x.xx.war

. http://mirrors.dedipower.com/ftp.apache.org/struts/examples/struts2-blank-2.0.14.war

You can download it and rename to .zip

and see how they set up the project.

WEB-INF / web.xml



must have struts2 servlets and filter

...    
<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-INF / classes / struts.xml should be in classes folder and should point to your struts config file

    ...
    <include file="yourconfig.xml"/>

      

* WEB-INF / yourconfig.xml in the same folder as struts.xml

and contains mappings for your actions

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

    <action name="*" class="example.ExampleSupport">
        <result>/example/test.jsp</result>
    </action>

    <!-- Add actions here -->
</package>

      

All jsp files are in the folder /example

0


source


I may be wrong, but for every action it goes to /test.jsp. But did you just create [application name] /index.jsp ?? Create [application name] /test.jsp and point there !? (try removing the slash in the xml file before test.jsp?)

0


source







All Articles