-3

On java (controller) i have a string that can contains an apostrophe. I send this string to the jsp page and the string is extracted on this way:

 var intestatarioLibString = '${libretto.intestatarioLib};

(I send the object libretto wich contains the string).

The problem is the apostrophe, if the string contains an apostrophe, the string is "cutted" where the apostrophe is. Sample:

If the string that i send is 'DEL PIERO' ALESSANDRO' , when i open the jsp on browser i met an error because the debugger read like:

 var intestatarioLibString = 'DEL PIETRO' ALESSANDRO

So, the apostrophe is considered the end of the string. The problem is that i CAN'T replace the apostrophe, i need it. Someone can give me a hand please?

RemovedQuasar
  • 35
  • 1
  • 11

2 Answers2

1

You need to escape the characters in javascript string, for this you can use org.apache.commons.lang.StringEscapeUtils.escapeJavaScript.

Ciro Spaciari
  • 621
  • 4
  • 10
0

You need to escape the string just try :

var intestatarioLibString = escape("DEL PIETRO' ALESSANDRO");
user1211
  • 1,467
  • 1
  • 18
  • 27