tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Dame" <>
Subject RE: Preserving Line Breaks in <c:out>
Date Wed, 16 Jul 2003 23:57:30 GMT
Thanks Serge. Your suggestion works great with one caveat:

I can't specify delims="\r\n" because those values are used literally.
However, this seems to work:

<% String newline = "\r\n"; pageContext.setAttribute("newline",
newline); %>
<c:forTokens items="${foo}" delims="${newline}" var="foo">

-----Original Message-----
From: Serge Knystautas [] 
Sent: Wednesday, July 16, 2003 3:01 PM
To: Tag Libraries Users List
Subject: Re: Preserving Line Breaks in <c:out>

Brian Dame wrote:
> Does anyone have tips on preserving line breaks in <c:out>?
> For example, a user enters text into a textarea, which is stored in a 
> database. When I retrieve the text from the database, I'd like to 
> display it formatted exactly as the user entered it.
> I can only think of two options:
> 1) Parse the text, insert <p> and <br> tags as needed, and set 
> escapeXml=false on the <c:out> tag
> 2) Hardwrap the text and use a <pre> tag or CSS equivalent around it.
> Anyone have other ideas?

This is close to 1), but use c:forTokens delims="\r\n".  In the loop, 
print each element with whatever <br> you want between them.

It's a bit more content in JSP, but then you don't have to worry about 
leaving some of the content unescaped.  I usually use <pre>.

Serge Knystautas
Lokitech >> software . strategy . design >> p.
301.656.5501 e.

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message