struts响应html中的字符编码问题
请考虑以下场景。我有一个带有属性的表单:
class MyForm extends ActionForm{
String myProperty;
... // getter & setters here
}
我在操作类中设置了此属性:
class MyAction extends Action{
... // execute method begins here
myForm.setMyProperty("<b>Hello World</b>");
... // execute method returns here
}
现在,当我打开相应的 JSP 页面时,我在应该显示 myProperty 的位置得到以下 html:
<b>Hello World</b>
这是错误的。它应该生成以下 html:
<b>Hello World</b>
有什么想法如何解决这个问题吗?
编辑
JSP代码如下:
<bean:write name="MyForm" property="myProperty"/>
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:
<b>Hello World</b>
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"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 escapeXml 属性来保留 HTML 格式:
Use the escapeXml attribute to preserve HTML formatting:
我从baijiu的回答中得到提示,并找到了解决方案:
只需设置filter =“false”即可按原样显示敏感字符,无需任何编码。谢谢白酒。
I got hint from baijiu's answer, and found the solution:
Simply setting filter="false" displays sensitive characters as they are, without any encoding. Thanks baijiu.