2

I am developing one spring application in which i have one form from which i am storing the data in database, it is working fine. But when i am trying to display it in my jsp page it did not show the data after the single quote('). Data is retrieved perfectly in my Controller but in my jsp page it did not show me the data after single quote(').

<input type="text" class="form-control gui-input textarea-grow sampleDynamicClassText" name='intervantionList[0].levelOfintervention' id="levelOfintervention" value='${ieProfileDO.intervantionList[0].levelOfintervention}'>

this is my jsp page code.

Jaimin Raval
  • 39
  • 1
  • 6

1 Answers1

0

Use either single quote or double quotes. Keep it consistent. Why your code was breaking was because your value='${ieProfileDO.intervantionList[0].levelOfintervention}' was enclosed in single quotes and your model value also had single quote. Something like value='world's best' which is invalid.

Change single to double quote. It should work now.

<input type="text" class="form-control gui-input textarea-grow sampleDynamicClassText" name="intervantionList[0].levelOfintervention" id="levelOfintervention" value="${ieProfileDO.intervantionList[0].levelOfintervention}">

If your variable value contains double quotes then you need to use a util to escape those double quotes.

You can refer to the following link, they are using org.apache.commons.lang.StringEscapeUtils.escapeHtml() from apache commons. https://stackoverflow.com/a/5741404/5039001

If you want to incorporate the html escaping method:

<input type="text" class="form-control gui-input textarea-grow sampleDynamicClassText" name="intervantionList[0].levelOfintervention" id="levelOfintervention" value="${org.apache.commons.lang.StringEscapeUtils.escapeHtml(ieProfileDO.intervantionList[0].levelOfintervention)}">

When it needs to be used multiple times, for a cleaner approach, you can create a custom EL function. You can check out this link: http://blog.idleworx.com/2010/04/custom-tags-and-custom-el-functions-in.html

Community
  • 1
  • 1
prem kumar
  • 5,641
  • 3
  • 24
  • 36
  • I used double quote(") instead of single quote(') and I also used the html escaping method which you suggested but, it is still not working. Now it did not show me the data after double quote("). Means the problem is till the same, if i use single quote in value attribute then it did not show me the data after single quote and if i use double quote then it did not show me the data after double quote. – Jaimin Raval Dec 29 '15 at 09:02
  • can you post that part of generated html code. your double quote after escaping should be like " – prem kumar Dec 29 '15 at 09:07
  • I directly wrote this in my code : – Jaimin Raval Dec 29 '15 at 09:19
  • i hope you have that apache commons jar and also can you post the html as seen in the view page source in the browser – prem kumar Dec 29 '15 at 09:22
  • or you can print the evaluated org.apache.commons.lang.StringEscapeUtils.escapeHtml(ieProfileDO.interv‌​antionList[0].levelOfintervention) in your log and paste this value – prem kumar Dec 29 '15 at 09:29
  • This is my view source page source code
    – Jaimin Raval Dec 29 '15 at 09:48
  • i think you dont have the apache commons jar. if your are using maven. org.apache.commons commons-lang3 3.4 and use this method org.apache.commons.lang3.StringEscapeUtils.escapeHtml4(String) as this is the latest version of this jar. – prem kumar Dec 29 '15 at 09:52
  • I would suggest you to write a main program in the same project. call this apache commons method and give your custom string input to the method as parameter and check. if this works fine without any errors... then it should work in your web application too – prem kumar Dec 29 '15 at 10:45