Search code examples
jspparsingjsp-tags

Render text in "<format>" in jsp as such


im stuck with a strange problem and im not sure of the solution.

I am getting data from a third party service in form of

"TEXT1<TEXT2>TEXT3 "

and so on.But when i try to render this on my JSP, the output becomes truncated in form of TEXT1TEXT3 because JSP interprets <TEXT2> as a tag and doesnot render it on output as text. Is there any way i can replicate the output as TEXT1<TEXT2>TEXT3 as such on JSP without making changes in the backend as i dont have any access to the same.

The problem is with the backend service as it is giving output in form of <> tags and not in form of "&lt;,"&gt;" Is there any way i can get the output to be shown as such, without having to change the backend.Are there any custom tags present in JSP libraries that can handle such behaviour?


Solution

  • use tag lib jstl add declaration at begining of jsp file

    <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
    

    if the Attribute is text try this in jsp file

    <c:out value="${text}" escapeXml="true"/>
    

    or

    <c:out value="${text}"/>
    

    instead of

    ${text}
    

    You can search jstl tag c:out for more information