• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 609
  • Last Modified:

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

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
  • 2
1 Solution
Jason C. LevineNo oneCommented:
Which server language are you using?  JSP or something else?
RockingAuthor Commented:
Jason C. LevineNo oneCommented:
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...

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now