Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

formatting the textarea form field in a servlet

 
Ulvi Cetin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a textarea field in an HTML form. When the user submits the form, a servlet inserts the content of the textarea in Oracle database.
When the contents of the textarea are retrieved from the database and displayed on a servlet or a JSP, line breaks and other formatting aren't displayed. I tried using the HTML PRE tag (preformatted), but that didn't fix the problem.
Any ideas on how to store the textarea in a database and/or how to display the retrieved contents from the database.
Thx.
Ulvi.
[ March 03, 2003: Message edited by: Ulvi Cetin ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to do with servlets really...
But other than line breaks, what kind are formatting are you talking about? Not much else is possible.
With regard to the line breaks themselves, are they coming back to you in the request parameter for the text area? If so, is something stripping them out going into or coming out of the DB?
The text area control has some funky behavior on various browsers, and there are a slew of non-standard wrap attributes that some older browsers supported but whose behavior is non-deterministic.
I'd suggest checking to see if the line breaks are being sent as part of the request parameter, and if not, reposting your question, along with the relevant HTML and handler code in the HTML forum.
hth,
bear
[ March 03, 2003: Message edited by: Bear Bibeault ]
 
Ulvi Cetin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear, thanks for your reply!
I tried to view the contents of the textarea in the servlet (the one that is supposed to insert them into the database). I got the contents by request.getParameter("contents") and displayed them by out.println(contents) and I don't see line breaks in this output either.
So, as you suggested, I think something is stripping the line breaks (before they are inserted in the database) between the form page and the servlet. But what??
Thx.
Ulvi.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the code for your textarea in a topic in the HTML forum.
hth,
bear
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell you what, I will just move this to the html forum.
 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can format the text area using JavaScript
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The textarea sends the newlines as newlines, and when you print those out in a JSP or servlet, it appears that way (with the newlines) in the HTML source, but that won't mean it makes a newline on the browser window.

Have you tried replacing "\n" with "<br />"
 
Ulvi Cetin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply! I just figured out that just before you replyed. I needed to parse the text (with StringTokenizer) and replace all the "\n" with "<br>".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic