I have a spring controller with the following code :
@RequestMapping(value="/getMessage.htm", method=RequestMethod.POST)
protected String uploadFile(ModelMap model){
//... other codes
model.addAttribute("theMessage", "Hello world <b>how are you</b> today?");
return "the-view";
}
In the client side (JavaScript), I show this message using the following code :
document.getElementById('theMessageSpan').innerHTML = '<c:out value="${theMessage}"/>';
But when it is displayed, it shows a string literal
Hello world <b>how are you</b> today?
I need to show the message as :
Hello world
how are you today?
I tried using apache commons' StringEscapeUtils.unescapeHtml
before putting the text in the ModelMap
, but the result is just the same.
Any thoughts?
I believe by default <c:out>
escapes XML. You'll need to explicitly tell it not to with
<c:out escapeXml="false" value="${theMessage}"/>
Can't find newer docs, but see here. Among the attributes, you have
escapeXml
Determines whether characters <,>,&,'," in the resulting string should be converted to their corresponding character entity codes. Default value is true.