0

In my JSP i am getting below value as string.

strFullContent:: 1BOOK OFFERS NO GUARANTEE OR WARRANTY THAT THE CRAFTS ARE WITHOUT ERROR. CRAFTS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND

In application below code is there.

input type="hidden" name="strFullContent" id="strFullContent" value="<%=objCraftsUploadDataBean.getStrFullContent() %>"/>

Now when I am printing value in JSP,complete value is getting printed. but when i am trying to get that value in js partial value is getting fetched.

var fullcontent =document.getElementById('strFullContent').value;

now this variable fullcontent contains only partial value.

fullcontent = 1BOOK OFFERS NO GUARANTEE OR WARRANTY THAT THE CRAFTS ARE WITHOUT ERROR. CRAFTS ARE PROVIDED

As per my understanding problem is due to " in value. But I don't know the solution.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Aditya
  • 185
  • 1
  • 2
  • 8
  • http://stackoverflow.com/questions/4526502/how-to-html-encode-in-the-jsp-expression-language , http://stackoverflow.com/questions/17919998/escape-all-strings-in-jsp-spring-mvc – user2864740 Jan 15 '14 at 07:30

2 Answers2

0

Change your input and use single quotes there instead of double quotes for value since value also contains those

value="<%=objCraftsUploadDataBean.getStrFullContent() %>"

can be

value='<%=objCraftsUploadDataBean.getStrFullContent() %>'

Or you can escape them if you still want to use double quotes.

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • Escaping is the only *correct* solution, IMOHO. The data wasn't expected to contain a `"` and so it broke. In the future, data might contain `'` and so it will break again. – user2864740 Jan 15 '14 at 07:23
  • That's also mentioned in the answer. – Hanky Panky Jan 15 '14 at 07:24
  • It's mentioned as a very small footnote without the rational found in my comment. – user2864740 Jan 15 '14 at 07:24
  • 1
    Tried the solution given by Hanky. It worked. but User2864740 is also correct. Can you please let me know how to escape special character ? – Aditya Jan 15 '14 at 08:00
0

Worth a try

strFullContent = strFullContent.replace(/"/g, '\\"');
pratim_b
  • 1,160
  • 10
  • 29
  • It would be better to replace `"` with `"` - or, best(er), use existing escaping support. – user2864740 Jan 15 '14 at 07:26
  • This is not Working. Getting below exception. – Aditya Jan 15 '14 at 07:59
  • ServletException in:/views/frame/CraftContent.jsp] Unable to compile class for JSP: An error occurred at line: 51 in the jsp file: /views/content/CraftUploadFive.jsp Syntax error, insert ")" to complete Expression 48: 49: 50: 51: "/> 52: 53: 54: An error occurred at line: 51 in the jsp file: /views/content/CraftUploadFive.jsp Invalid character constant 48: 49: 50: 51: "/> 52: 53: 54: Stacktrace:' org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 51 in the jsp file: /views/content/CraftUploadFive.jsp Syntax error, insert ")" to complete Expression 48 – Aditya Jan 15 '14 at 07:59
  • Do it on your String input – pratim_b Jan 15 '14 at 08:09