You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Allen <da...@mojavelinux.com> on 2003/06/23 22:49:34 UTC

Re: Escaping ' and " in bean:write output for javascript?

Kruse, Matt (MKruse@aquent.com) wrote:

> Simple question,
> 
> When I want to use <bean:write> to print a value into a JSP, to be included
> as an argument in a javascript function, how can I escape the output in
> cases where it has ' and " and newline characters?
> 
> For example,
>   addName('<bean:write name="person" property="lastname"/>');
> 
> If the "lastname" is O'Reilly, this causes a javascript error because the
> output looks like:
>   addName('O'Reilly');
> When it SHOULD look like:
>   addName('O\'Reilly');
> 
> I don't see anything in the docs to handle this - do I need to extend
> bean:write with my own taglib?

One way would be to escape the quotes using the string taglib from
jakarta.  It is based on jstl and it has the ability to do very
basic string manipulation.  You would use the expression lanague
however to specify your var, such as ${person.lastname}.

http://jakarta.apache.org/taglibs/doc/string-doc/

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
"Personally, I'm not finding Windows 
to be less expensive to administer, 
but those security holes--that'll kill 'em," 
-- Al Gillen, IDC
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org