Struts 6.x migration issues with sitemesh

43 views Asked by At

I am trying to migrate a working project from Struts-core 2.5.30 to 6.3.0.2 running on a JBoss EAP 7.4. Meanwhile i am using struts2-convention-plugin, struts2-oval-plugin, struts2-json-plugin, freemarker and struts2-sitemesh-plugin for my page layout.

When upgrading to Struts 6.3.0.2, the HTML tags inside the ${body} of the sitemesh (the body consists of freemarker pages), are printed instead of rendered.
Below is a screenshot of a small demo page with struts 2.5.x and strits 6.3

Struts 2.5.x

enter image description here

Same page with Struts 6.3

enter image description here

I have tried the same simple project without the use of sitemesh and the content seems to be rendered correctly. It seems that something is not working probably correct with sitemesh. Also i see no errors in my logs.

Below the source of the project

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts configuration 6.0//EN"
        "https://struts.apache.org/dtds/struts-6.0.dtd">


<struts>
    <constant name="struts.devMode" value="true" />

    <constant name="struts.devMode" value="${struts.development.mode}" />
   <constant name="struts.convention.default.parent.package"
              value="basicstruts2" />
    <constant name="struts.convention.action.suffix" value="Action"/>
    <constant name="struts.convention.action.mapAllMatches" value="true"/>
    <constant name="struts.convention.classes.reload" value="${struts.convention.classes.reload}" />
    <constant name="struts.convention.package.locators" value="actions,action" />
    <constant name="struts.convention.package.locators.disable"  value="false" />
    <constant name="struts.convention.package.locators.basePackage" value="com.sample.action" />

    <constant name="struts.locale" value="de_DE" />

    <!-- Configuration for JBoss -->
    <constant name="struts.convention.exclude.parentClassLoader"
              value="true" />
    <constant name="struts.convention.action.fileProtocols" value="jar,vfsfile,vfszip" />

    <constant name="struts.devMode" value="false" />



    <package name="basicstruts2" extends="struts-default">




        <result-types>
            <result-type name="json" class="org.apache.struts2.json.JSONResult" />
        </result-types>

        <action name="index">
            <result>/index.jsp</result>
        </action>

        <action name="hello" class="com.sample.action.HelloWorldAction" method="execute">
            <result name="success">WEB-INF/content/hello-world.ftl</result>
        </action>
    </package>
</struts>

pom.xml

  <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <struts.version>6.3.0.2</struts.version>
    </properties>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>


    <dependency>
        <groupId>org.ow2.asm</groupId>
        <artifactId>asm</artifactId>
        <version>9.5</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-core -->
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>${struts.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-convention-plugin</artifactId>
        <version>${struts.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.javassist</groupId>
                <artifactId>javassist</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-sitemesh-plugin</artifactId>
        <version>${struts.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts2-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-json-plugin</artifactId>
        <version>${struts.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-oval-plugin</artifactId>
        <version>${struts.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-context</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts2-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>



</dependencies>
<build>
    <finalName>struts-demo</finalName>
</build>

web.xml

    <?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>Basic Struts2</display-name>
<welcome-file-list>
    <welcome-file>index</welcome-file>
</welcome-file-list>


<filter>
    <filter-name>struts-prepare</filter-name>
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
</filter>

<filter>
    <filter-name>struts-execute</filter-name>
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts-prepare</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>struts-execute</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
    <servlet-name>sitemesh-freemarker</servlet-name>
    <servlet-class>org.apache.struts2.sitemesh.FreemarkerDecoratorServlet</servlet-class>
    <init-param>
        <param-name>default_encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>sitemesh-freemarker</servlet-name>
    <url-pattern>*.ftl</url-pattern>
</servlet-mapping>


<listener>
    <listener-class>org.apache.struts2.dispatcher.listener.StrutsListener</listener-class>
</listener>

hello-world.ftl

<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Some title</title>
  </head>
  <body>

  <h1>A H1 Header</h1>
  <div>

    ${test}
  </div>
  </body>
</html>

decorators.xml

<decorators defaultdir="/WEB-INF/content/decorators">
    <decorator name="main" page="main.ftl">
        <pattern>/*</pattern>
    </decorator>
</decorators>

sitemesh.xml

    <?xml version="1.0" encoding="UTF-8" ?>
<sitemesh>
    <property name="decorators-file" value="/WEB-INF/decorators.xml" />
    <excludes file="${decorators-file}" />

    <page-parsers>
        <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
    </page-parsers>

    <decorator-mappers>
 
        <mapper class="com.opensymphony.module.sitemesh.mapper.ParameterDecoratorMapper">
        </mapper>
       
        <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
            <param name="config" value="${decorators-file}" />
        </mapper>
    </decorator-mappers>
</sitemesh>
0

There are 0 answers