The moose likes Servlets and the fly likes textarea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "textarea" Watch "textarea" New topic


Relu Ovidiu

Joined: Mar 18, 2004
Posts: 12
I enter a text like this (in the textarea) :
I want to save this in the database(mysql) an then, read from db and put on the screen(webpage) exactly as i entered in the textarea (with the newlines,etc.). How can i do that? .. because when a read from db and put on the screen the text looks like this: aaaaaabbbbbbccccc...THNX!...( i don't want to use html tags( like .<br>.) when i enter the text)
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

This is not a servlet question, it's an HTML formatting issue.
The easiest way to do it is to output the data between presentation tags <pre></pre>, or you can look at CSS and find the style settings to retain formatting. The default in HTML is to treat it all as white space and ignore it.
BUT that's only if the line feeds are being retained in the database. It would be worth checking the data to make sure it's being retained correctly first.
ch praveen
Ranch Hand

Joined: Mar 08, 2004
Posts: 67
Iam facing the problem of how to store newlines in sqlserver database from a jsp page which gets data from a textarea in a html page. Can anyone suggest how to store newlines in a sqlserver database.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

I'm not sure they are the same problem. Relu, did this help?
'ch', your post may be better in the JDBC firum, but I can't move this thread there because of the original post. Can you post some of your code?
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
my suggestion is, use substring on the textarea string and put in individual columns, hence when you retrieve you can easily modify your output as you want.
hope this helps.
Chris Davis

Joined: Mar 07, 2004
Posts: 10
The problem is that when you enter the text in a textarea, new lines are in fact return characters. HTML does not use the return character to display text on a new line. What I do to solve this problem is replace all '\n' characters with a string containing "<br>". This will format your text the way you want in html. I also remove all '\r' characters since you no longer need that character.
Hope this helps.
Relu Ovidiu

Joined: Mar 18, 2004
Posts: 12
The <pre> </pre> it's working (..for the moment)... THNX a lot! ...
I agree. Here's the link: http://aspose.com/file-tools
subject: textarea
Similar Threads
Pop-Up Window and getParameter()
what is wrong with my code? trouble extracting input from Textarea
JEditorPane html
Formatted text display.
How to reassign STDIN to a JTextArea??