Reputation: 11
I am working on an application in Java. I need to take the formated HTML data from an object and display it in a displaytag constructed table. However, it seems like by default, displaytag supress the formatting by escapeHTML the content so my format won't display properly.
Like I used the formatted data to highlight the matching search words in tag: <SPAN style='background-color:yellow;'></SPAN>
. The infomation displayed in the search result was literal syntax. instead of the yellow background of the word.
How can I unescape the HTML so it can display the highlighted background?
I am ready tried to use the escapeXml attribute. However, the app failed due to invalid attributes.
Thanks,
Upvotes: 0
Views: 2120
Reputation: 1108537
That's odd. As per displaytag documentation XML escaping is by default disabled. Are you sure that you don't have escapeXml="true"
somewhere in the tags?
Another cause could be that you're using JSTL <c:out>
tag to display individual values. It does by default escape XML. You can disable it by adding escapeXml="false"
attribute to the tag.
Upvotes: 3
Reputation: 298818
Do I understand correctly that you want to un-escape escaped HTML code? You can do it something like this:
public static String unescapeHtml(final String input){
return input
.replace("<", "<")
.replace(">", ">")
.replace("&", "&")
.replace(""", "\"");
}
Upvotes: 0