• Post Reply Bookmark Topic Watch Topic
  • New Topic

New Line character in JSTL c:set  RSS feed

 
Sam Drake
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
chang Anne
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
 
chang Anne
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I would like to try new line in jstl run_time tag, but I get the following
errorsrg.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?
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hello,
I just want to try add a new ('\n') in JSTL.
Thank your suggestion.
 
Jarek Lipski
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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 ]
 
Steve Perkins
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!