Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

\n in a string for output

 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm building a string in a for loop and would like to have a new line separator in my string. At this point I have the following:
strT50 += paramKey+" - "+strPercent+"; \n";
I also tried <br> instead of \n.
In both cases, the output in a webpage doesn't show as a new line.
Can someone please tell me how to format a string in jsp so that it containes new lines when needed?
Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember, you're emitting HTML so the <br> should have worked for you -- the \n will obviously not.

Look at the HTML that is sent to the browser to determine why it's not laying out as you wish.
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use <br> in
strT50 += paramKey+" - "+strPercent+"; <br>";

my webpage enterptites it literally and shows "<br>" for some reason...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are emitting it with <cut>, the output will be HTML-encoded. Look up the attiributes to <cut> to see how to make it stop doing that.
[ August 01, 2006: Message edited by: Bear Bibeault ]
 
Stefan Evans
Bartender
Posts: 1755
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you outputting this string "strT50"?
If you are doing it with a <cut> tag, it will automatically escape the < and > characters into < and >

You could make it <cut value="${strT50}" escapeXml="false"/>

An alternative while still using the "\n" character is to surround the string you are printing out with <pre> tags in the html.
The <pre> tag tells HTML the text is pre-formatted, and shouldn't be modified according to the normal rules.

<pre><cut value="${strT50}"/></pre>

Hope this helps,
evnafets
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very nice! escapeXml="false" worked well!
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic