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
Second
Third : from the CONSOLE
Any idea how to solve that ?
Regards
“\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.
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.
\n and 0xa are exactly the same thing.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With