Thanks Lukasz,

In the end it turned out to be the Javamelody filter which created the issue. We'll do some more digging to see if we can resolve but we are happy to disable javamelody for now to finally move to testing using 7.1.1 and Tomcat 11.

Z.




On 18/10/2025 9:52 pm, Lukasz Lenart wrote:
I used Claude Code to analyze this problem and I got a big document
(attached), but you can try this for now:

- [ ] Enable WARN logging for
`org.apache.struts2.util.FastByteArrayOutputStream`
- [ ] Reproduce the truncation and check logs for encoding warnings
- [ ] Identify the exact character position where truncation occurs
- [ ] Examine the character(s) at and immediately after the truncation point
- [ ] Verify `struts.i18n.encoding` is set to "UTF-8"
- [ ] Verify JSP `pageEncoding` and `contentType` both specify "UTF-8"
- [ ] Check if SiteMesh is decorating the JSON response (should be excluded)
- [ ] Compare `response.getCharacterEncoding()` between Tomcat 10 and Tomcat 11
- [ ] Test with JSON plugin instead of JSP rendering
- [ ] Check for any custom filters or interceptors that wrap the response

Cheers
Łukasz

sob., 18 paź 2025 o 04:12 Zoran Avtarovski <[email protected]> napisał(a):
Hi Guys,

We are almost ready to go into final testing on our Struts 7 app
migration, except for a small issue when we render JSON responses and we
can't work out where the issue is.

The problem presents when we try and render JSON response to a jsp page,
but only when going through an action first. I should stress this works
fine on tomcat 10 using the same build of Struts and SiteMesh.

As a simple test we created a method on our action class which sets a
page accessible parameter to a long sample JSON string:

         public String ajaxTest(){
              ajaxResponse = " [{\"name\": \"Adeel
Solangi\",\"language\": \"Sindhi\",\"id\": \"V59OF92YF627HFY0\",\"bio\":
... I have attached the full JSON text but cropped in the email for clarity
              return SUCCESS;
          }

On the resulting jsp page, see below, it results in the JSON string
being cropped and the browser complaining of invalid JSON:

<%@ page contentType="application/json; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%><s:property
value="%{ajaxResponse}" escapeHtml="false"/>

We also tried using JSTL tags which has the same result:

<%@ page contentType="application/json; charset=UTF-8" %><%@ taglib
uri="jakarta.tags.core" prefix="c"%><c:out value="${ajaxResponse}"
escapeXml="false"/>

The strange part is if we set the variable in the JSP page and just call
the page directly via testPage.jsp it works as expected:

<%@ page contentType="text/html;charset=UTF-8" language="java"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:set var="ajaxText">
      [{"name": "Adeel Solangi","language": "Sindhi","id":
"V59OF92YF627HFY0","bio": "Donec lobortis eleifend condimentum. ...
</s:set>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
      <head>
          <title>SpareEngine</title>
          <meta http-equiv="Content-Type" content="text/html;charset=utf8" />
      </head>
      <body>
          <div class="main-body">
              <s:property value="%{ajaxText}" escapeHtml="false"/>
          </div>
      </body>
</html>

Because the plain JSP renders correctly I don't think it is a tomcat
issue, but I can't be certain. Any help would be appreciated.

Z.




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to