java Struts <bean:write> 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4397648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Struts <bean:write> tags
提问by Switch
How do I escape character like '&' in struts tags. For example we can mention.
如何在 struts 标签中转义像 '&' 这样的字符。例如我们可以提及。
<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.
我正在迭代一个书单数组 (booklist) 并一个一个地设置书名。在这种情况下,我需要在 'title' 属性中转义像 '&' 这样的字符,以便为该特定操作执行相应的逻辑。
Thanks.
谢谢。
回答by Buhake Sindi
Maybe use the filter
attribute?
也许使用filter
属性?
<bean:write name="booklist" property="title" filter="true" />
More on <bean:write>
. The documentation states:
更多关于<bean:write>
. 文档指出:
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.
如果此属性设置为
true
,则将针对 HTML 中敏感的字符过滤呈现的属性值,并且任何此类字符将替换为其实体等效项。
回答by Naved
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.
我想您想在 URL 栏上显示书名(或在 URL 中使用它)。
并且某些书名在其标题中包含“&”。
如果是这样?您必须将其替换为“%26”。
在您设置集合的操作中替换它。
如果您是从数据库中获取它,则在 sql 查询中替换它。