In the JSP page, we assign some java variable values to javascript variables and vice versa for some time. When doing so, we face problems for the characters like Single quote, double quote and back slash (\). Is it necessary to take care of these characters specially or by designing some different way we can avoid this problem?

I found that, some web sites text box and text area components are failing whenever such special characters are entered.

Could you please help me for the right design? Thank you in advance.