Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

776 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