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.
The bean tag is a combination of the set and push tags, it allows you create a new instance of an object and then set the values of the variables. It then makes the bean available in the valuestack, so that it can be used in the JSP page. The Bean tag requires a java bean to work with.
You can create Struts HTML tags from the Struts HTML Tags drawer. These tags are used to create Struts input forms, as well as other tags generally useful in the creation of HTML-based user interfaces. The output is HTML 4.01 compliant or XHTML 1.0 when in XHTML mode.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With