Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to store the newlines entered by enter key in textarea?

 
M K Rayapudi
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to store the text entered in a TEXTAREA control in the database, and retrieve when ever required.
Here the problem is It is not storing the new line characters (enter key), it is storing all the lines as ONE sentence.
I tried using different values for wrap attribute.(soft, hard, physical,virtual, etc), but no use.

Please help in this regard.
Thank you.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you reading, storing, and writing the value out?

Eric
 
M K Rayapudi
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:How are you reading, storing, and writing the value out?

Eric

I am using the javascript as follows:
 
M K Rayapudi
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still the problem not resolved
Please help .
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For HML, a newline character is just whitespace, and will be displayed as a space character. If you want an actual line break to appear on the HTML page,. you'll need to convert all newline characters to "<br/>" before displaying them.
 
M K Rayapudi
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Dittmer.
I need to store the content from the TEXTAREA in the table
and retrieve the same from TABLE and populate into that TEXTAREA.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not storing the new line characters

At which point along the code are the newline characters dropped? Are they still present when the servlet receives the form? Are they present in the DB? Are they present when the data is retrieved from the DB? Are they present when the JSP with the TEXTAREA is created?
 
M K Rayapudi
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
It is not storing the new line characters

At which point along the code are the newline characters dropped?

While storing into the table.

I am retrieving the form data in a servlet using request.getParamter(); if I print the content of the TEXTAREA character by character as int by casting , it is showing new line as 13 & 10 (two characters). After this I am storing this value in a TABLE, in the table it is storing as one string instead multiple lines (means no special characters are stored at the new line character positions)
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should dig into the DB connectivity to see why it's dropping those characters. SQL and JDBC don't arbitrarily alter data they're handling, so some other piece of code may be involved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic