'HTTP Status 404 while running struts2 application

I'm using Java SE-11, struts 2.5.29, tomcat 10.0.6 in my program. I'm trying to create a small project using struts-2 framework. I have declared all the filters in the web.xml as mentioned on the struts.apache.org for the particular version of Struts. Still I'm unable to execute my program successfully. I think there is some error either in the jar files or something else which I'm not able to identify.

I have already tried older version of Struts 2.3.27 and even older version of tomcat9 but it didn't gave me the correct results.

Here is my web.xml and struts.xml code for reference.

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="https://jakarta.ee/xml/ns/jakartaee"
    xmlns:web="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="5.0">
    <display-name>Strut2Implementation</display-name>

    <welcome-file-list>
        <welcome-file>index.html</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>

struts.xml:

<struts>
    <package name="default" extends="struts-default">
        <action name="welcome" class="org.action.WelcomeAction">
            <result name="success">/success.jsp</result>
            <result name="failure">/error.jsp</result>
        </action>
    </package>
</struts>

the jars which I have added are

commons-fileupload-1.4
commons-io-2.6
commons-lang3-3.8.1
commons-lang-2.4
commons-logging-1.2
freemarker-2.3.30
javassist-3.20.0
ognl-3.1.29
struts2-core-2.5.29
struts-dwr-plugin-2.5.29
xwork-core-2.2.3
xwork-jar.jar

The error which I'm getting is
SEVERE: Exception starting filter [struts2] java.lang.ClassCastException: class org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter cannot be cast to class jakarta.servlet.Filter



Solution 1:[1]

You use different servlet version on the servlet container. This version is not backword compatible with the version of Struts you have used.

See Apache Tomcat Migration Gude:

There is a significant breaking change between Tomcat 9.0.x and Tomcat 10.0.x. The Java package used by the specification APIs has changed from javax... to jakarta.... It will be necessary to recompile web applications against the new APIs.

Tomcat can convert an existing web application from Java EE 8 to Jakarta EE 9 at deployment time using the Apache Tomcat migration tool for Jakarta EE. To make use of the feature, the web application should be placed in the Host legacyAppBase folder (by default named webapps-javaee) and they will be converted to an equivalent Jakarta EE web application in the Host appBase folder (by default named webapps).

Alternately, the Apache Tomcat migration tool for Jakarta EE or any similar conversion tool can be used ahead of time to benefit from faster deployment time and more precise conversion configuration options.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Roman C