Solved

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

Posted on 2014-02-21
3
578 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now