Yeah, that's all I could come up with too. There really should
be a more graceful technique built into JSP...

I wrote two custom tags. One to replace " with " for
input field values and another to insert a backslash before quotes
for use within javascript code.

Jeff

----- Original Message -----
From: "Lance Lavandowska" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 02, 2002 2:55 PM
Subject: Re: Dealing with embedded quotes in dynamic values


> We added a method to our StringUtils class that replaces " with &quot;
> and then call that whenever we're placing a String into an input form that
> uses the value="" format:
> <input type="text" name="myfield", value="<%=
StringUtils.replaceQuotes(myBean.getStringValue()) %>" />
>
> Your javascript problem is not clear, but if the above does not work, you could try
escaping " with \", or change them to ' (single-quote).
>
> Lance
>
> ----- Original Message -----
> From: "Jeff Larsen" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, April 02, 2002 1:04 PM
> Subject: Dealing with embedded quotes in dynamic values
>
>
> > Does anyone have any good references or ideas on
> > how to deal with embedded quotes in JSP? For example,
> > if I have the following in my JSP:
> >
> > <input type="text" name="myfield" value="<%= myBean.getSomeStringValue() %>">
> >
> > the value is not properly displayed if the result of the myBean value
> > has double quotes embedded in the string. It get's even worse if you
> > need to embed a JSP value in Javascript because misplaced quotes will
> > generally result in a scripting error in the browser.
> >
> > Jeff
>
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://archives.java.sun.com/jsp-interest.html
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>  http://www.jguru.com/faq/index.jsp
>  http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to