Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts <bean:write> tags

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.

like image 394
Switch Avatar asked Dec 09 '10 11:12

Switch


People also ask

What are tags on beans?

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.

What are Struts tags?

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.


2 Answers

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.

like image 190
Buhake Sindi Avatar answered Sep 22 '22 00:09

Buhake Sindi


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.

like image 38
Naved Avatar answered Sep 25 '22 00:09

Naved