0

Hello i have this code in my jsp

<a href="#"onclick="supprimerProduit('<bean:write name="gererProduitsForm"  property="type_produit.nomProduit"/>','supprimerProduit','',<bean:write name="gererProduitsForm"  property="type_produit.idProduit"/>)"></a>

So i have an javascript error when i have for example

Thoma's

in my var

<bean:write name="gererProduitsForm"  property="type_produit.nomProduit"/>

How can i do for escape the apostrophe..? Thx

Mercer
  • 9,736
  • 30
  • 105
  • 170
  • Hi, Mercer! Isn't your questin a duplcate of http://stackoverflow.com/q/1470768? – brandizzi Apr 27 '11 at 13:36
  • perhaps but how can i use this http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/StringEscapeUtils.html#escapeJavaScript%28java.lang.String%29 in my jsp ? – Mercer Apr 27 '11 at 13:38
  • possible duplicate of [How to escape apostrophe or quotes on a JSP ( used by javascript )](http://stackoverflow.com/questions/1470768/how-to-escape-apostrophe-or-quotes-on-a-jsp-used-by-javascript) – no.good.at.coding Apr 27 '11 at 13:43

1 Answers1

-1

@brandizzi: This subject is different from the other one you linked to. Escaping an apostrophe on a db insert/update, or stripping an apostrophe on db select is a horse of a different color. Escaping an apostrophe in a url string, like the example in the original post here is a whole different kettle of wax.

To Mercer, this is my recommendation for escaping the apostrophe in a url string: Replace ' with %27

The javascript way to do it is like this:

my_title = "Who's to say we aren't all a dream?";

my_title = my_title.replace("'", "%27");

The PHP way to do it is:

$my_title = "Who's to say we aren't all a dream?";

$my_title = str_replace("'","%27",my_title);

Gregory Lewis
  • 701
  • 5
  • 2
  • Sorry, this answer is far from useful. In JavaScript it's too late already and the OP is not using PHP, but JSP with Struts. – BalusC May 28 '11 at 15:38