| Author |
Keeping line breaks from a String
|
Arthur Colombo
Greenhorn
Joined: Apr 21, 2011
Posts: 11
|
|
Hi, I've tried a few searches both here and in the servlet session, but to no avail.
What I want is to print a String that comes from a Servlet in a JSP page through a JSTL command. To do this, I'm currently setting an attribute with said String and printing it with c: out.
The problem is, being a string, the \n line breaks don't work, and trying to add <br> instead doesn't add a line break when viewing in the JSP either, instead printing it.
So, I'd like to know what I should use to create line breaks in a String that'll persist and correctly show in a JSP page with c: out.
Currently, its something similar to this
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
<br> is the correct way as line breaks are invisible whitespace to an HTML page.
The reason that isn't working for you is that you are using <c:out> incorrectly. Look up the documentation for the tag to see what you are doing wrong.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
|
And Welcome to JavaRanch!
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
Arthur Colombo
Greenhorn
Joined: Apr 21, 2011
Posts: 11
|
|
As the documentation points out:
escapeXml - Determines whether characters <,>,&,'," in the resulting string should be converted to their corresponding character entity codes. Default value is true.
Therefore:
Thanks for the help
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
|
Bear in mind that if the string you are emitting with escapeXml enabled comes from a user, you are opening yourself up for injection attacks. Use this technique only for trusted data.
|
 |
Arthur Colombo
Greenhorn
Joined: Apr 21, 2011
Posts: 11
|
|
|
The string which I am actually using in my project is created in the servlet and kept there, so that should pose no risk for the moment. Still, good to know that.
|
 |
 |
|
|
subject: Keeping line breaks from a String
|
|
|