• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Handling apstrophe with JSTL

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All

I am doing something like this in my jsp:
I have an image on clicking of which print.jsp opens up.
This print.jsp is getting a parameter from the parent window i.e conutry code.
The code for this is as follows:


And the code for image is as follows:



mypopup() is a java script function.
My problem is coutryCode paramter contains apostrophe in it.
Which is creating problems for me.
If i try fn:replace like this :



It gives compilation err in jsp i.e. syntax is wrong in jsp.
If anybody has any idea please help me.
Thanks a lot in advance.
[ January 10, 2008: Message edited by: Khushwinder Chahal ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With all the &lt conversions and smilies in your posted code, I'm having a hard time reading it. Please go back and edit your post to use < and >, and click the disable smilies checkbox so that your colons do not get converted.
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear Bibeault,

I have done as per your saying.
Now please look at my problem.
Thanks
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear Bibeault,

You have closed duplicate post.
Now please answer my this post if you have any idea.
Thanks a lot
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi anybody has any idea please advise me
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think nobody has
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Khushwinder Chahal, Patience Is AVirtue

You've asked at midnight, 1, 3, and 4 in the morning US time.
Surely, you don't expect people to wake up in the middle of the night to answer your question, do you?
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben Souther
As per your suggestion i waited for 1 week but there is still no reply of this
post.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your syntax looks right.
I just tried this with the following sample and it worked:


What container (and version) are you using?
Do you have the correct version of the JSTL jar files for that container?
Have you added the taglib import directive to the top of your JSP?
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your feedback Ben.
I want to explain my problem little bit more.
As you have done in the example it is working fine and it is also working fine
on my system but my problem is same but its formate is little bit different.

My actual code is :

<c aram name="genericName" value="${StoneForm.genericName}"/>
${fn:replace(genericName, "'", "\\'")}

Here you can clearly see the in the value field of the param tag i do not have
the simple value as you are giving in your example i have the variables as you can see. Now when i try like the above code it gives java script err.
(on the onclick() function as i m sending the params with scripts and it contains apostrophe....)
And if i give replace function inside value field it gives syntax err in jsp.
Please try to do like this.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Khushwinder Chahal:

Here you can clearly see the in the value field of the param tag i do not have
the simple value as you are giving in your example i have the variables as you can see.



In my example, I made a point of loading the string into a variable with c:set before trying to transform it with the fn:replace function.

Maybe I'm still missing something?
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben
Now just have a look at the difference
in my case it is like:

value="${StoneForm.genericName}"

and in your case it is like:

value="O'Brian's Bakery"

In your case it is static string but in my case its a string in the form
of variable.
Now we can see the difference and replace function works in both the cases.
But problem arises in javascript. Just have a look at my first post.It will clear the things.
Its giving err on the following line:

<html:image srcKey="image.print" on click="mypopup('${print}')>
because the print variable contains ' apostrophe in it.
Please try to do it if you have some time.
Thanks a lot.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about this ?


(remove the spaces)
[ January 23, 2008: Message edited by: Christophe Verre ]
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Christophe Verre
It solved my problem.
 
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic