1

Struts 2 Annotations are not working with Java 8.

I have the following example that worked with Java 7, but giving the error in Java 8.

I guess the errors is related to Libraries and Java 8.

Does anyone have this problem?? If so how do we solve it???

I am using struts 2.3.15.1 with Java 8 and Apache Tomcat 8.

This example is working successfully with Java 7, struts 2.3.15.1 and Apache Tomcat 8. I just tested both.

When i am using Java 8 it gives the following error:

> HTTP Status 404 - There is no Action mapped for namespace [/] and
> action name [test] associated with context path [/s2demo].

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

    <listener>
        <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
    </listener>   

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

TestAction.java

package action;

import org.apache.struts2.convention.annotation.Result;


@Result( name="success", location="/test.jsp")
public class TestAction {


     public String execute() {
         return "success";
     }
}

test.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Test Successful!</h1>
    </body>
</html>

Libraries that are included in this project are :

asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-beanutils-1.8.0.jar
commons-digester-2.0.jar
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
files.txt
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
log4j-1.2.17.jar
ognl-3.0.6.jar
struts2-convention-plugin-2.3.15.1.jar
struts2-core-2.3.15.1.jar
struts2-tiles-plugin-2.3.15.1.jar
tiles-api-2.0.6.jar
tiles-compat-3.0.1.jar
tiles-core-2.0.6.jar
tiles-jsp-2.0.6.jar
tiles-servlet-3.0.1.jar
xwork-core-2.3.15.1.jar
Roman C
  • 49,761
  • 33
  • 66
  • 176
pragada
  • 11
  • 1
  • 2

1 Answers1

1

According to Lukas Lenart, the Struts 2 maintainer,

S2 isn't JDK8 compatible, it will be case for S2.5

This was stated on June 18, 2014 on the Struts 2 mailing list (struts-user). See http://mail-archives.apache.org/mod_mbox/struts-user/201406.mbox/ajax/%3CCAMopvkN0MKKt%2BPs3Cv8gjTDO4X6MjnxFV3GFs8wsqUuNxOtrkQ%40mail.gmail.com%3E