wood burning stoves 2.0*
The moose likes JSP and the fly likes \n in a string for output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "\n in a string for output" Watch "\n in a string for output" New topic
Author

\n in a string for output

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
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

Joined: Jan 10, 2002
Posts: 61217
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
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

Joined: Jan 10, 2002
Posts: 61217
    
  66

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

Joined: Jul 06, 2005
Posts: 1018
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

Joined: Apr 11, 2006
Posts: 134
Very nice! escapeXml="false" worked well!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: \n in a string for output