Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When adding "\n" to a Java String , the newline is not presented in a JSP but on stdin it does

When I pass a java string back to my servlet , the servlet passes that string to the jsp .

The string holds names & addresses with a new line "\n" , but when I'm trying to present that on the screen , I see a full line , however on the console the new-line is presented .

Here's a snapshot : First enter image description hereSecond enter image description hereThird : from the CONSOLE

enter image description here

Any idea how to solve that ?

Regards

like image 270
Jack cole Avatar asked Aug 10 '12 11:08

Jack cole


People also ask

What does \n do in Java string?

“\n” is an Escape Character in Java that is used to enter a new line in the output. It is also known as the end of line or line break. It is a platform-dependent line separator, mostly used to break a line because of its easy syntax.

Can we use \n in Java?

In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.

What is the equivalent of \n in Java?

\n and 0xa are exactly the same thing.

How do you tell if a string is newline?

Use the in operator to check if a string contains a newline character, e.g. if '\n' in string: . The in operator will return True if the string contains a newline character and False otherwise.


1 Answers

In HTML, newline characters are treated like spaces, and multiple spaces are displayed as a single space. If you want to go to the next line, you must transform newline characters into <br />, or enclose your text inside a <pre></pre> block.

like image 119
JB Nizet Avatar answered Oct 03 '22 07:10

JB Nizet