Struts <bean:write> tags

浪子不回头ぞ 提交于 2019-12-07 05:43:43

问题


How do I escape character like '&' in struts tags. For example we can mention.

<a href="./testaction.do?testmethod=bookResult&bookTitle=<bean:write name="booklist" property="title"/>" class="nLink"><bean:write name="booklist" property="title"/></a></small>

I'm iteration over a book list array (booklist) and setting book titles one by one.In this scenario I need to escape characters like '&' within the 'title' property in order execute the respective logic for that particular action.

Thanks.


回答1:


Maybe use the filter attribute?

<bean:write name="booklist" property="title" filter="true" />

More on <bean:write>. The documentation states:

If this attribute is set to true, the rendered property value will be filtered for characters that are sensitive in HTML, and any such characters will be replaced by their entity equivalents.




回答2:


I suppose that you want to show the book title on URL bar (or use it in the URL).
And some of the book title is having '&' in their title.
If so? you have to replace it with '%26'.
Replace this in the action where you are setting the collection.
If you are fetching it from DB, then replace it in sql query.



来源:https://stackoverflow.com/questions/4397648/struts-beanwrite-tags

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