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
Joined: Jun 13, 2000
Posts: 3340
posted
0
You could try: <c:set var="tempStr" scope="page" value="${someStr + '\n'}" /> EL will concatenate the String with the \n character.
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
Joined: Jul 02, 2003
Posts: 29
posted
0
Hello,
chang Anne
Greenhorn
Joined: Jul 02, 2003
Posts: 29
posted
0
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
Joined: Jul 28, 2000
Posts: 1825
posted
0
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
Joined: Jul 02, 2003
Posts: 29
posted
0
Hello, I just want to try add a new ('\n') in JSTL. Thank your suggestion.
Jarek Lipski
Greenhorn
Joined: Sep 06, 2008
Posts: 1
posted
0
In JSP 2.0: open string literal using " or ', press enter and close string literal :-)
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.