2

I have a problem at this example

I work with eclipse for Java EE and Apache Tomcat 8. My project structure:

http://s29.postimg.org/xtevpxgef/stackstruts2.png

The web.xml code:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Hello World 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.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

     <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

The other files code is the same as the struts website. When I run the index.jsp file I get the following error:

**HTTP Status 404 - /helloworld/index.jsp

type Status report
message /helloworld/index.jsp description The requested resource is not available.**

Can someone spot the reason why can't I run it?

Roman C
  • 49,761
  • 33
  • 66
  • 176
user3590899
  • 135
  • 2
  • 10

1 Answers1

1

First of all the project is created by using Maven configuration, and to access the Struts action you should use url

Step 6 - Build the WAR File and Run The Application

Execute mvn clean package to create the war file.

Copy the war file to your Servlet container. After your Servlet container successfully deploys the war file go to this URL http://localhost:8080/helloworld/index.action where you should see the following:


(source: apache.org)

Web application context is where the application was deployed. In the docs url it's /helloworld, on the image it's /Hello_World_Struts2_Ant. Use it as a part of the url. It doesn't matter which app context did you use during deployment but url depends on it. If you want to change the web app context you should read Java - How to change context root of a dynamic web project in Eclipse. After the context you use action name with .action extension to execute action.

Don't use URLs like localhost:8080/helloworld/index.jsp because you might not get the resource because it's already handled by the web server.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • I changed the context root to "app" and I used the action name with the .action at the URL but I got the same message again. Am I still doing something wrong? Or it needs maven structure to work? I used exactly the same project structure shown as at the image, not the maven structure. – user3590899 Feb 18 '16 at 16:21
  • 1
    You should not get the same message again, if you did what is said in the tutorial. Of course you need a maven to work with, without it it doesn't work. – Roman C Feb 18 '16 at 17:16