• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encoding and decoding TextArea contents

 
Parthasarathy Venkatavaradhan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
Parthasarathy
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, make sure you have the wrap attribute set to hard to preserve the linebreaks, tabs, ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic