• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

New Line character in JSTL c:set

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to append a new line character('\n') at the end of a string and then display it so that they come one below the other.
I tried something like this -
<c:set var="tempStr" scope="page" value="${someStr}\n" />
This is not working. Can somebody tell me the correct way of going about it.
Thanks in advance,
Sam.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try:
<c:set var="tempStr" scope="page" value="${someStr + '\n'}" />
EL will concatenate the String with the \n character.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, I hope you realize, HTML rendering ignores white space. If you output a new line character into html, the source gets the new line but, when rendered all white space gets mushed down to a single space.
If you want this rendered on a new line in html ouput, you need to put a <br> after it.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
 
chang Anne
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I would like to try new line in jstl run_time tag, but I get the following
errors:org.apache.jasper.JasperException: /SimpleBean.jsp(11,0) "${header['User-Agent']+ '\n'}" contains invalid expression(s): javax.servlet.jsp.el.ELException: Encountered "'\n", expected one of [, , , "true", "false", "null", "(", "-", "not", "!", "empty", ]
And my code runs in jsp2.0
Any ideas?
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chang,
Why dont you look at the suggestion by Carl and at the br tag in the end like the one given below
 
chang Anne
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I just want to try add a new ('\n') in JSTL.
Thank your suggestion.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In JSP 2.0: open string literal using " or ', press enter and close string literal :-)

For example:

${fn:replace(text, "
", "<br/>")}

Regards,
Jarek
[ September 06, 2008: Message edited by: Jarek Lipski ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There may be other ways to accomplish this, but here's a method that worked for me. Near the top of the page, I declared a variable holding the newline character:



I was then able to use this variable in an expression down in the "<pre>" block:



Hope this helps someone who stumbles across this page by using the same Google terms as I did.
 
Evil is afoot. But this tiny ad is just an ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic