aspose file tools*
The moose likes JSP and the fly likes EL - Problem rendering String with quote Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "EL - Problem rendering String with quote" Watch "EL - Problem rendering String with quote" New topic
Author

EL - Problem rendering String with quote

Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
The following works fine as long as the names do not have a quote. For example, a name such as O'brien causes an error when the JSP is rendered. Is there a function that will help to encode or handle this situation?

Thanks!

<td>${member.lastName}</td>
<td>${member.firstName}</td>


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

What kind of error?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
It's actually a JavaScript error because I am building variables to be passed into a javascript methjod when the option button is selected. But I am thinking it's because EL is not handling the quote correctly.

The following also causes an error ONLY if the names contain a quote.


<c:set <c:set var="mInfo" value="'${status.count}','${member.firstName}','${member.lastName}', '${member.sex}', '${member.relationshipCode}'" />


The actual Javascript error is - Error expected ')'

I guess the quote in the name is throwing it off to make it thinks it's the end of a string.
[ August 16, 2007: Message edited by: Bosun Bello ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Well, yeah. Your JSP is just going to create a page to send to the browser. If that page contains badly formatted JavaScript, the browser will complain no matter how the page was generated.

When you're going to emit text that will be embedded in a JavaScript string, you need to make sure that any quotes (of either type) are properly escaped.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL - Problem rendering String with quote