I have saved quotation(") in a string using escape character i database. That is working ok. But when i am retrieving the value in a jsp field from database, the string is being ended at the first quotation it gets in the whole string. I am giving an example below:

Lets take a string that i have stored in database as -

" Hello David. This is a "customer"."

Now, i am somehow need to save the string back from databse into a hidden field in a jsp page like below-

<input type="hidden" name="string_from_database" id="string_from_database" value="<%=some varibale that holds the data from database%>">

issue is - Part of the string is getting exposed (means it is being written on top of the page) which i do not want. In this case,the below phrase is written on the beginning of the jsp page, which i don't want.

customer".

kindly suggest on how to resolve this issue.

2

There are 2 answers

0
Secondo On

Use Jstl rather than scriptlets for further Explanation

use EL - Expression Language (${variable}) to get the Value eg. ${welcome}

<c:out value="${some varibale that holds the data from database}"/>
2
ostrgard On

Using this function you could replace the quote marks with the html entity variant &quot;. Here's a simple function for it. Hope it fits into your templating system, but should be easy to modify if not.

function escapeQuotes(str){
    return str.replace(/"/g,'&quot;');
}

Here's a working fiddle