Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL - Problem rendering String with quote

 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of error?
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic