my dog learned polymorphism*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "textarea" Watch "textarea" New topic
Author

textarea

Relu Ovidiu
Greenhorn

Joined: Mar 18, 2004
Posts: 12
I enter a text like this (in the textarea) :
aaaaaaa
bbbbb
cccccc
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
Rancher

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.
Dave.
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
Rancher

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?
Dave
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
hi,
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.
regards,
ravi
Chris Davis
Greenhorn

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.
-Chris
Relu Ovidiu
Greenhorn

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