Solved

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

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

630 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