Struts 2 textfield convert apostrophe to “&#39 ;”

♀尐吖头ヾ 提交于 2019-12-24 00:46:30

问题


I am trying to populate name text field with already saved value.

Now the value can contain apostrophe. But text fields is converting apostrophe to "&#39 ;".

Eg. sdsd'sds ==> sdsd&#39 ;sds

escape property for textfield is not working.

What should I do?


回答1:


You are getting this because of Encoding feature. To avoid this and get exactly same as you want, you have to use HtmlDecode which is available in util package of java.




回答2:


You are probably escaping it server-side.

Don't.

Struts will take care of this.

You only need to specify when you want the opposite (getting the unescaped value in the <s:property /> tag) using the escapeHtml="false" property.


P.S: there are characters that need a special threatment like the € (euro symbol), but it's another story.




回答3:


This issue got resolved with use of ESAPI.encoder().decodeForHTML() function. The values getting rendered properly after I decode the values before using in s:textfields.

Thanks.



来源:https://stackoverflow.com/questions/34436841/struts-2-textfield-convert-apostrophe-to-39

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!