This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
The moose likes Servlets and the fly likes Line Breaks when displaying HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Line Breaks when displaying HTML" Watch "Line Breaks when displaying HTML" New topic
Author

Line Breaks when displaying HTML

Steven Fischer
Greenhorn

Joined: Jun 28, 2001
Posts: 5
Here's an issue I've been working with lately. I have a bunch of text in a database, and when I display it with JSP, I want to interpret the hidden line break characters (\n, etc), as <br> tags. I have a handle on how to do it (StringTokenizer, String.indexOf()), etc., but I can't seem to search for the right sequence of characters. I thought it went like this .. line breaks on Unix were \n, line breaks on mac were \l, PC had \n\l. I guess this isn't working.
Can someone help me out?
Thanks a lot!
Steve
Bhupinder Dhillon
Ranch Hand

Joined: Oct 12, 2000
Posts: 124
I always use these methods...

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12868
    
    5
Wouldn't it be easier to use one of the input stream methods that have a readLine() method? What form does the database return the text in?
Bill
Steven Fischer
Greenhorn

Joined: Jun 28, 2001
Posts: 5
Thanks for your help .. Bill, to answer your question, I am getting a string using the Recordset object rcdSet.getString("dbasefield") method.
Steven Fischer
Greenhorn

Joined: Jun 28, 2001
Posts: 5
Bhupinder,
Your code recommendations worked out excellent. Thanks a ton!
Steve
 
jQuery in Action, 2nd edition
 
subject: Line Breaks when displaying HTML