Solved

How to output mysql multiline data in the same format with JSP and HTML?

Posted on 2014-02-21
3
591 Views
Last Modified: 2014-02-22
I just started learning how to make a website. I'm making a comment box which is used to enter blog entries. Let's say I types in an entry with 3 lines, and it will show up the same format in mySQL table. But when i try to output it, it becomes one line.

how to display the three lines in the same way as they were input by user
0
Comment
Question by:Rocking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 39878045
Which server language are you using?  JSP or something else?
0
 

Author Comment

by:Rocking
ID: 39878077
JSP
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 39878154
Okay, there are a couple of ways to skin the cat.

The easiest is to wrap the output with a CSS rule
<p style="white-space: pre;">
...JSP statement here...
</p>

Open in new window


The slightly more difficult way involves parsing the output through a function:

public String NLtoBR(String msg)
{
  msg = msg.replace("\n","<br>");
  return msg;
} 

Open in new window


The above simply parses whatever is in msg and replaces the newline character with the line-break HTML tag.
0

Featured Post

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Link Anchor Not working 9 67
What kind of script/language created this graph? 6 65
SSL unsecure page mystery 17 46
Can't Find The Code 15 19
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The viewer will learn how to dynamically set the form action using jQuery.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question