Error while upgrade to Struts 6 with struts jquery plugin

1.3k Views Asked by At

We have upgraded to Struts 6.0.0. The project Struts 2 jquery plugin version 4.0.3. When loading a page we face this error:

Could not load the FreeMarker template named 'div':
Attempted: /template/jquery/div.ftl
Attempted: /template/xhtml/div.ftl
Attempted: /template/simple/div.ftl
The TemplateLoader provided by the FreeMarker Configuration was a: org.apache.struts2.views.freemarker.FreemarkerThemeTemplateLoader
Could not open template

The stack trace cause is:

Caused by: freemarker.core.ParseException: Syntax error in template "template/jquery/div.ftl" in line 22, column 43:
Using ?html (legacy escaping) is not allowed when auto-escaping is on with a markup output format (HTML), to avoid double-escaping mistakes.
    at freemarker.core.FMParser.BuiltIn(FMParser.java:1225)
    at freemarker.core.FMParser.PrimaryExpression(FMParser.java:595)
    at freemarker.core.FMParser.UnaryExpression(FMParser.java:707)
    at freemarker.core.FMParser.MultiplicativeExpression(FMParser.java:822)

The line 22 in file template/jquery/div.ftl is as:

<#if parameters.id??> id="${parameters.id?html}"<#rt/></#if>

I am not familiar with Freemaker and I hope I could find a flag or something to by pass this.

I see the migration guide at https://cwiki.apache.org/confluence/display/WW/Struts+2.5+to+6.0.0+migration and also https://struts.apache.org/tag-developers/tag-syntax#escaping-body-of-a-tag but could not find the issue

I try to set struts.ui.escapeHtmlBody this in struts.xml but it did not help.

1

There are 1 best solutions below

0
Alireza Fattahi On

According to https://github.com/struts-community-plugins/struts2-jquery, for struts 6.0 the struts jQuery plugin 6.0 must be used.

enter image description here

Changing below in pom.xml fix it

 <dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-plugin</artifactId>
    <version>5.0.0</version>
</dependency>
<dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-grid-plugin</artifactId>
    <version>5.0.0</version>
</dependency>
<dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-datatables-plugin</artifactId>
    <version>5.0.0</version>
</dependency>
<dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-richtext-plugin</artifactId>
    <version>5.0.0</version>
</dependency>
<dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-tree-plugin</artifactId>
    <version>5.0.0</version>
</dependency>