• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

\n in a string for output

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are emitting it with <c:out>, the output will be HTML-encoded. Look up the attiributes to <c:out> to see how to make it stop doing that.
[ August 01, 2006: Message edited by: Bear Bibeault ]
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you outputting this string "strT50"?
If you are doing it with a <c:out> tag, it will automatically escape the < and > characters into < and >

You could make it <c:out 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><c:out value="${strT50}"/></pre>

Hope this helps,
evnafets
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very nice! escapeXml="false" worked well!
 
bacon. tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic