user962206
user962206

Reputation: 16147

Error 404 upon Start up of Struts2 in tomcat

I was making this hello world application using Struts2 and I've encountered an

HTTP Status 404 - /HelloStruts2/

Here is my web.xml

<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_3_0.xsd" version="3.0">
  <display-name>HelloStruts2</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

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

</web-app>

Here is my 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="basicstruts2" extends="struts-default">

        <action name="index">
            <result>WEB-INF/index.jsp</result>
        </action>

        <action name="hello" 
            class="actions.HelloWorldAction" method="execute">
            <result name="success">/HelloWorld.jsp</result>
        </action>

    </package>

</struts>

Here are the list of jars in my application

commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-logging-api-1.1.jar
freemarker-2.3.19.jar
javassist-3.15.0-GA.jar
jstl-1.2.jar
ognl-3.0.5.jar
struts2-core-2.3.7.jar
xwork-core-2.3.7.jar

Upvotes: 2

Views: 5456

Answers (4)

Kulbhushan Chaskar
Kulbhushan Chaskar

Reputation: 353

I had same problem, and i struggled to solve it for many hours, even i placed proper jars mentioned above.

I have faced this problem because there are too many jars files under the folder common->lib of the apache tomcat causing the issue.

So

1) Keep jars and there dependency neatly 2) Check jars under the lib folder of your web-inf for the dependency. 3) check jars containing same classes but having different version.

I found solution when i uninstalled tomcat and re-installed it.

Upvotes: 0

user962206
user962206

Reputation: 16147

I Have fixed it, It turns out that I just need the commons-lang jar to may lib directory.

Upvotes: 2

Mayuran
Mayuran

Reputation: 708

Try the following code segment in web.xml(in the struts filter user the pattern *.action)

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

Upvotes: 1

MRX
MRX

Reputation: 1651

this is problem of jars. please check with following jars. i had same problem and i resolved with following jars.

commons-fileupload-1.2.1
commons-io-1.3.2
commons-logging-1.0.4
commons-logging-api-1.1
freemarker-2.3.16
javassist-3.14.0-GA
log4j-1.2.16
ognl-3.0
struts2-core-2.2.1.1
xwork-core-2.2.1.1

Upvotes: 0

Related Questions