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.



Attachment: sample_long.json
Description: application/json

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

Reply via email to