wood burning stoves 2.0
The moose likes JSP and the fly likes Encoding and decoding TextArea contents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Encoding and decoding TextArea contents" Watch "Encoding and decoding TextArea contents" New topic

Encoding and decoding TextArea contents

Parthasarathy Venkatavaradhan

Joined: Oct 10, 2002
Posts: 8
I have text area where the user can enter any ascii character. I am retrieving them through my JSP code and storing it in the Database. when i try to retrive from DB and return it as an HTML page, how do i preserve the characters so that the formatting is as entered by the user. This includes newline, spaces, ''', '""' etc...
Thanks for the help in advance.
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
ok so when you enter the data in the DB using SQL make sure you use a PreparedStatement. This will then escape any characters that might intererfere with the SQL syntax. You do not need to deal with any of the encoding and decoding of the characters through the HTTP transfer because your container will do that. If you are displaying it as text in HTML then you will need to convert newlines in to <br /> which you can do by just using the String replaceAll method or of course just use the HTML <pre> tag to wrap the whole thing. If you are displaying it in another text area you dont need to wory about that.

Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33106

Also, make sure you have the wrap attribute set to hard to preserve the linebreaks, tabs, ...

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link: http://aspose.com/file-tools
subject: Encoding and decoding TextArea contents
It's not a secret anymore!