aspose file tools*
The moose likes JSP and the fly likes Replacement of c:url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Replacement of c:url" Watch "Replacement of c:url" New topic
Author

Replacement of c:url

Min Huang
Greenhorn

Joined: Sep 21, 2004
Posts: 16
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.


SCJP, SCJD, SCBCD, SCWCD
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

What would you want to do that? What is <c:url> not doing that your proprietary version would do?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Min Huang
Greenhorn

Joined: Sep 21, 2004
Posts: 16
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

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

Joined: Sep 21, 2004
Posts: 16
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

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

Joined: Sep 21, 2004
Posts: 16
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

My pleasure!
Min Huang
Greenhorn

Joined: Sep 21, 2004
Posts: 16
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

Joined: Sep 21, 2004
Posts: 16
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Replacement of c:url