• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to print saved textarea in line by line in jsp  RSS feed

 
Anuvinaya vysyaraju
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Whenever I'm saving data from textarea it is saving including enter keys from textarea,while retrieving that from database I'm getting continuous string not in line by line.Please tell me how to print that textarea in line by line in my page.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just a couple of guesses that may help..

have you tried including the text whithin a <pre> tag?

or you could try to replace the newline character with <br/> before displaying the text..
 
Michael Angstadt
Ranch Hand
Posts: 278
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that the text isn't being sanitized in any way? It's possible that the newlines are being taken out either (1) before being added to the database or (2) after being retrieved from the database.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, by far the most likely... (3) the newlines are being ignored by the browser because they are in HTML and not inside a <pre> element.
 
Michael Angstadt
Ranch Hand
Posts: 278
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran a quick test by creating an HTML page with a textarea element that looked like this:



The text appeared as two separate lines at least for me (using Firefox).
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, you're right, I missed that option too. But notice that Anuvinaya vysyaraju said the data came from a text area. Didn't say it was being written to a text area. You're right, writing it in the <textarea> tags would preserve the line endings as well.
 
Michael Angstadt
Ranch Hand
Posts: 278
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds to me like his (her?) problem is that he has some form with a textarea. The form is submitted and the text (with newlines) in the textarea is saved to a database. Then, that same text is later retrieved from the database and put inside another textarea. But the textarea that's being populated with text from the database is not recognizing the newlines in the text. Is this accurate?
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue is with the HTML (not necessarily JSP). Most browsers will understand the "wrap" attribute of the textarea tag, even if it's not officially a "valid" attribute.


Different IDEs might flag that attribute as invalid, and there's no guarantee that attribute will work five years from now (I'd be surprised if it didn't), but that should solve the issue for almost any browser. And worse case, it ignores the attribute, and leaves you without the newlines, but no worse off than you are now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!