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
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply 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: 1506
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: 56233
    
  13

What kind of error?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
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: 56233
    
  13

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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: EL - Problem rendering String with quote
 
Similar Threads
Image not dispalyed in one JSP but dispalyed in other
how to obtaine grid in html page?
JSP creating html rows for displaying data
width of HTML table cell
Scroll table within a table not working