Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 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