Handling Special Characters in JSP

Hi

Iam getting Item Name from Data Base that contains Sp Chars like ',"/- etc. When Iam displaying the same it is throwing java script error(; expected). Also when sending the same via URL to new window also it is throwing exceptions.

How to handle this?

Regards

B S Reddy

[306 byte] By [Bijjama] at [2007-11-26 17:40:10]
# 1

When you output a string to javascript that contains quotes, you may end up with illegal syntax, something like this:

alert("hello, my name is "gimbal2"");

What you need to do is escape the quotes that you output, so it becomes this:

alert("hello, my name is \"gimbal2\"");

You could do that with the String replace() method.

gimbal2a at 2007-7-9 0:08:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...