• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to escape a single quote.  RSS feed

 
Dave Bosky
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm looping through a collection of beans, extracting an item description
and passing the value to a javascript function.

The item description may contain single quotes which causes my javascript function to fail.

How can I escape all single quotes in a JSP String variable before passing to my javascript function?

Thanks,
Dave
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several methods in the String class that you could use:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

A lot of these weren't available until 1.4 though. If your app needs to support older versions of Java, check the older APIs.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!