wood burning stoves 2.0*
The moose likes JSP and the fly likes Handling apstrophe with JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Handling apstrophe with JSTL" Watch "Handling apstrophe with JSTL" New topic
Author

Handling apstrophe with JSTL

Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
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 ]

Khushwinder
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
Hi Bear Bibeault,

I have done as per your saying.
Now please look at my problem.
Thanks
Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
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

Joined: Oct 03, 2007
Posts: 128
Hi anybody has any idea please advise me
Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
I think nobody has
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
Hi Ben Souther
As per your suggestion i waited for 1 week but there is still no reply of this
post.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Oct 03, 2007
Posts: 128
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Oct 03, 2007
Posts: 128
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.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

What about this ?


(remove the spaces)
[ January 23, 2008: Message edited by: Christophe Verre ]

[My Blog]
All roads lead to JavaRanch
Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
Thanks a lot Christophe Verre
It solved my problem.
 
 
subject: Handling apstrophe with JSTL
 
Similar Threads
fn:trim question
Struts Forward in to new Window
c:param manipulations in jstl
Using EL expresion in c:url
Struts and Popup