Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

URL Encoding in "a href"  RSS feed

 
Anuja Piplapure
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

On my JSP, there is an "a href" element, where the href is created out of data elements. This data element may contain special characters like '+' or '&' or '-' or '_'. When the page is rendered and the href is created, I need these to get encoded, but somehow it is not working for me.
I have tried few things:



This gives JSP compilation errors.

I also tried using a javascript function which onClick of the href, would encode it, but that does not work.

Can someone please tell me some way of effectively doing this ?

Thanks in advance.
Anuja
[ January 05, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot mix scriptlets and custom actions in that way. Your biggest stumbling block seems to be the <bean:write> tag. What does that do? I assume that it emits the property of the named scoped variable? What scope is the bean in?

You'll need to figure out how to access that data using different mechanisms.

For constructing URLs, the best way is with the <c:url> tag from the JSTL.

What version of JSP are you using? Are you set up with the JSTL? If not, why not?
[ January 05, 2006: Message edited by: Bear Bibeault ]
 
Anuja Piplapure
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

Yes, I have realised that the <bean:write> is posing a problem here. But since all my pages are making use of Struts, the coding is done that way. I am not really sure what I can do to get the data differently.

But I would surely like to know how I can encode the URL without the scriptlets in an a href ?

Thanks. Regards.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anuja Piplapure:
I am not really sure what I can do to get the data differently.


If you are going to use frameworks like Struts, you really need to become familiar with the mechanisms it uses. Otherwise, when situations like this arise, you get stuck.

If "equipment" is a scoped variable, in request scope perhaps, you can access it using the EL if you are trying to avoid scriptlets. Otherwise, you'll probably need to retrieve it using scriptlet code.

Originally posted by Anuja Piplapure:
But I would surely like to know how I can encode the URL without the scriptlets in an a href ?


Well that's exactly what <c:url> is all about.

Would you care to answer my other questions?
[ January 05, 2006: Message edited by: Bear Bibeault ]
 
Anuja Piplapure
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this is the first time I am working with Struts, there is plenty that I still need to know. And I agree that not knowing has got me stuck here.

Yes, "equipment" is scoped variable from request scope.

I am using Jakarta Struts 1.1. Am not set up for JSTL as I am not really aware of its usage. Like I mentioned earlier, this being my first use of Struts, I am not using its more sophisticated aspects.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!