wood burning stoves
The moose likes JSP and the fly likes double quotes handling in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "double quotes handling in jsp" Watch "double quotes handling in jsp" New topic

double quotes handling in jsp

chetana kotamreddy

Joined: Nov 20, 2006
Posts: 3
Here is the jsp code where i am facing the problem:

<logic:iterate id="resultItem" name="results" type="com.aon.concert.model.custom.IBISAccountData" indexId="index">
resultsArray[<%=index%>] = new ResultItem(
"<bean:write name="resultItem" property="userId"/>",
"<bean:write name="resultItem" property="unitCode"/>",
"<bean:write name="resultItem" property="unitDesc"/>"

Here in the user name if double quotes are present in the database, java script error is coming.

Please help...
Rusty Smythe
Ranch Hand

Joined: Aug 09, 2006
Posts: 93

Where's the code to


??? Your question is full of red herring, no details and you haven't shown the problem.

We can't help you if you don't give the required info...
chetana kotamreddy

Joined: Nov 20, 2006
Posts: 3
The data class contains only the getter and setter methods. So, i have not given the code.We are using to get the name of the user. So, in the Action class i am handling the double quotes by calling the escapeDoubleQuotes method in which i am appending \\\ characters to " to escape it. But in the pop up window \ is also displayed.

Here is teh code for escapeDoubleQuotes:

public static String escapeDoubleQuotes(String sourceString) {
int quotePos = 0;
StringBuffer formatStr = new StringBuffer("");
if(sourceString.indexOf('"',0) > -1){
quotePos = sourceString.indexOf('"',0);
formatStr.append(sourceString.substring(0,quotePos)).append("\\\"") ;
sourceString = sourceString.substring(quotePos+1,sourceString.length());
if (sourceString != "") formatStr.append(sourceString);
else {

I am calling this method before i send the value to the data class. Now the double quote is not giving the javascript error, but in th epop up window \ character is also displayed. But when i select the record, in the main page ectra \ character is not getting displayed. Only the user name is displayed. Can you please suggest why \ character is displayed in the popup jsp.
I agree. Here's the link: http://aspose.com/file-tools
subject: double quotes handling in jsp
It's not a secret anymore!