• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

textarea

 
Relu Ovidiu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <pre> </pre> it's working (..for the moment)... THNX a lot! ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic