-3

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

 var intestatarioLibString = '${libretto.intestatarioLib};

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

The problem is the apostrophe, if the string contains an apostrophe, the string is "cut" 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. Can someone can give me a hand please?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
RemovedQuasar
  • 31
  • 1
  • 13

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
  • 630
  • 5
  • 10
0

You need to escape the string just try :

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