• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replacement of c:url

 
Min Huang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm looking for a way to replace <c:url/> with my own version, which does URL encoding. I have thought of just using <myc:url/> instead, but the former option is preferable.

Is there an easy way to do this without manually modifying the jstl jar? Any help or ideas would be appreciated.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would you want to do that? What is <c:url> not doing that your proprietary version would do?
 
Min Huang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URL encoding; eg transform a relative url like /search/��� into /search/%FF%D0%D1, for example.

Also, a form submission isn't an option either.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah yes, any <c:param> will be encoded, but the base url will not.

Rather than trying to subvert the <c:url:tag> I'd create an EL function that encoded the value passed to <c:url>. So you'd end up with something like:


[ March 29, 2007: Message edited by: Bear Bibeault ]
 
Min Huang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do would an EL function would be better? I've considered these options:

a) Replace <c:url/>
b) Write <myc:url/>
c) Write an EL function and do <c:url value="${myc:encode(url)}"/>
d) Encode in a servlet and set the encoded url in the model

I prefer option a) because I already have a lot of JSP's to modify, but c) is still on the table if there is a compelling reason to choose it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would not choose (a). Firstly, it's going to be difficult to do. You'll need to replace the code in the JSTL with your own. Now, you've got a proprietary Version of the JSTL that you need to keep in sync. And architecturally, it's just wrong. You will have replaced standard behavior with custom behavior. Would you replace java.lang.String with your own custom version? Of course not. Leave the standards standards. Otherwise, you're just asking for future troubles.

As I said, I'd go with (c) and with (b) a close second.
 
Min Huang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea. I agree with your thoughts on a), overriding standard behavior is a whole other can of worms altogether, and I think I'll just go with b). Thanks for your input.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure!
 
Min Huang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If anybody was following this, (and Mr. Bibeault, you're not going to like this), you can do this:

1) Write your own CustomUrlTag, possibly extending UrlTag.

2) Copy the c.tld from standard.jar into /WEB-INF/tld and rename it to something like custom.tld.

3) Modify the url tag in c.tld and change the class name to your custom url tag.

4) Put the following in your web.xml:
 
Min Huang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if you don't want to nefariously subvert the <c:url/> tag, you can use jakarta's string taglibs that has a <str:encodeUrl/> tag.

--
edit: messed up the url
[ March 29, 2007: Message edited by: Min Huang ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic