Skip to Main Content
Jakarta Struts Cookbook
book

Jakarta Struts Cookbook

by Bill Siggelkow
February 2005
Intermediate to advanced content levelIntermediate to advanced
528 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from Jakarta Struts Cookbook

3.10. Filtering Text Input

Problem

You want to render data containing HTML tags, and you want that data to be interpreted and processed by the browser as HTML markup.

Solution

This is about as simple as it gets:

<bean:write name="myForm" property="freeText" filtered="false"/>

You can allow unfiltered values when using JSTL:

<c:out value="${myForm.freeText}" escapeXml="false"/>

Discussion

When you use the Struts bean:write tag to generate text, by default any special characters sensitive to HTML processing are replaced with their entity equivalents. For example, the greater than character (>) is replaced with the &gt; character entity. This feature is known as response filtering and is enabled by default. In most cases, the filtering is desired, as an unfiltered response can be misinterpreted by the browser. Table 3-4 shows the characters and the corresponding replacement entities that are filtered by the bean:write tag.

Table 3-4. Filtered characters

Character name

Character value

Replacement entity

Less than

<

&lt;

Less than

>

&gt;

Ampersand

&

&amp;

Double quote

"

&quot;

Backslash

\

&#39;

Sometimes, however, you want rendered text to include HTML tags. Suppose you had an online journaling application that allows a user to enter text that will be displayed on a page. Allowing HTML permits the user to use tags that make text appear in bold or italics. The text could contain hyperlinks, different font sizes, and images. In other situations, your application ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Jakarta Struts

Programming Jakarta Struts

Chuck Cavaness
Beginning Spring Framework 2

Beginning Spring Framework 2

Bruce Snyder, Sing Li, Anne Horton, Thomas Van de Velde, Naveen Balani, Christian Dupuis
Java Cookbook

Java Cookbook

Ian F. Darwin
Struts 2 in Action

Struts 2 in Action

J. Scott Stanlick, Chad Michael Davis, Donald J. Brown

Publisher Resources

ISBN: 059600771XSupplemental ContentErrata Page