views:

333

answers:

2

Hi

Please consider the following scenario. I have a form with a property:

class MyForm extends ActionForm{
    String myProperty;
    ... // getter & setters here
}

I set this property in action class:

class MyAction extends Action{
   ... // execute method begins here
   myForm.setMyProperty("<b>Hello World</b>");
   ... // execute method returns here
}

Now when I open the respective JSP page, I get following html at the point where the myProperty is supposed to be displayed:

&lt;b&gt;Hello World&lt;/b&gt;

Which is wrong. It is supposed to generate following html:

<b>Hello World</b>

Any ideas how can this problem be solved?

EDIT

The JSP code is as following:

<bean:write name="MyForm" property="myProperty"/>
+1  A: 

Use the escapeXml attribute to preserve HTML formatting:

//your view *.jsp
<c:out value="${myProperty}" escapeXml="false"/>
baijiu
A: 

I got hint from baijiu's answer, and found the solution:

<bean:write name="MyForm" property="myProperty" filter="false"/>

Simply setting filter="false" displays sensitive characters as they are, without any encoding. Thanks baijiu.

craftsman