1

I am passing a value as request attribute to the jsp page.

request.setAttribute("description", StringEscapeUtils.escapeHtml("Hello 1F World (Hello World) Hello World"));

In jsp Page I am setting in the pageContext

String text = (String) (String) request.getAttribute("description");
pageContext.setAttribute("description", text);

I have to send this text as a request parameter to the server. When I look in the firebug I see an error. I am trying to use "value" = "${text}" which throws an error. What am I doing wrong?

SyntaxError: unterminated string literal
[Break On This Error]   

{ "name": "description", "value": "
Cœur
  • 37,241
  • 25
  • 195
  • 267
user525146
  • 3,918
  • 14
  • 60
  • 103
  • You forgot to show the code involved with sending the text to the server. Exactly how do you do that? *edit* I can guess that you're dropping that string into some JavaScript code on the page. You need to use something like a JSON encoder tool to ensure you get a valid JavaScript string constant. – Pointy Apr 03 '13 at 18:49
  • yes, I am putting that text back in the javascript code, in an iframe to send that value as an ajax. – user525146 Apr 03 '13 at 18:54
  • Well the problem is that you need to make sure that the string is properly formatted so that the JavaScript parser accepts it as a valid string constant. The easiest way to do that is to use a JSON encoder. There's not such a thing in the standard JSTL function library, unfortunately. – Pointy Apr 03 '13 at 18:56

1 Answers1

2

You should use StringEscapeUtils.escapeJava going by the content of your string which doesn't have any HTML

StringEscapeUtils.escapeJava("Hello 1F World (Hello World) Hello World"));
hop
  • 2,518
  • 11
  • 40
  • 56