I have some problem with auto-encoding HTML tags to UTF-8 in Struts 2 tag.
I want to pass a value witch contains a HTML tag from action class to JSP page, but in Struts tag this value is automatically encoding to UTF-8 and HTML tag is not correctly displayed.
For example:
I have a String
variable named param
in the action class:
String param=param[0] + "& <br>" + param[1];
And this param
is passing to JSP page and displayed in the page using Struts tag:
<s:property value="%{param}">
My problem is, that in JSP page <br>
tag is encoding automatically and displeyed like <br>
instead of using it like a HTML tag.
Does anyone have an idea, how could I skip this automatically encoding process?
Have you tried the (documented) attribute escapeHtml
?
<s:property value="%{param}" escapeHtml="false" />
PS: Two additional notes:
You are using the character &
, which is special in HTML . If you are not going to escape the string, you should write it as &
As Rowan C aptly points out in his answer, using unescaped html in a web page can be dangerous, especially if the string (in your case the param
array) is dynamic and can be set by the client. If you can't trust or properly sanitize it, then don't do that. Seriously.