Matt Southard
Matt Southard

Reputation: 71

Struts2 isn't loading my webapp...404 error?

I am a complete newbie to Struts2 and am unable to run anything involving it on tomcat in either eclipse/browser. Tomcat is working fine when I am just mapping servlets/jsp in a web.xml file, but when trying to switch to struts2 I can't get it to work. When I try to run on the server it isn't even going to my index jsp...just loading a 404 error. I followed an online tutorial when I couldn't get my app for my class running and the tutorial I can't get to run either. Here are the jar files I have added to tomcat lib/build path jars -

asm-5.0.2.jar             
asm-commons-5.0.2.jar       
asm-tree-5.0.2.jar         
commons-fileupload-1.3.1.jar      
commons-io-2.2.jar     
commons-lang3-3.2.jar   
commons-logging-1.1.3.jar   
commons-logging-api-1.1.jar   
freemarker-2.3.19.jar   
javassist-3.11.0.GA.jar   
ognl-3.0.6.jar    
struts-core-1.3.10.jar    
struts2-dojo-plugin-2.3.20.jar    
xwork-core-2.3.20.jar    

filter added to web.xml -

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>
     org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
 </filter>

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

struts xml -

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="helloworld" extends="struts-default">

  <action name="hello" 
        class="com.struts2.files.HelloWorldAction" 
        method="execute">
        <result name="success">/HelloWorld.jsp</result>
  </action>
</package>
</struts>

Any ideas as to why I am getting a 404 when trying to run the app?

Upvotes: 0

Views: 264

Answers (2)

Learner
Learner

Reputation: 21435

The filter class org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter belongs to Struts2 but you are using struts1 jar file struts-core-1.3.10.jar

As Ravi suggested, download the Jar file from Struts-2.3.20

Upvotes: 1

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51721

I guess, you've added the wrong struts-core-1.3.10.jar to your classpath. That probably belongs to Struts 1.x. You need to include the latest struts2-core-2.x.x.jar from the Struts 2 framework.

A typical Struts 2 application has the following jars under WEB-INF/lib directory.

commons-fileupload-1.2.1
commons-io-1.3.2
commons-logging-1.1
freemarker-2.3.13
junit-3.8.1
ognl-2.6.11
xwork-2.1.2
struts2-core-2.1.6
struts2-convention-plugin-2.1.6 (if using annotations)

Try downloading the latests jars from struts.apache.org.

Upvotes: 1

Related Questions