I want to capture the base path of a given url
http://mydomain.com/mypath/coolpath/favoritepath/file.htm
so basically i just want this:
/mypath/coolpath/favoritepath/
Any ideas how to do this without using straight Java?
I want to capture the base path of a given url
http://mydomain.com/mypath/coolpath/favoritepath/file.htm
so basically i just want this:
/mypath/coolpath/favoritepath/
Any ideas how to do this without using straight Java?
This functionality doesn't exist in JSTL. Closest is the
fn:replace()
, but it doesn't support regular expressions. The other functions provides the possibility to get rid of the leading part until with the domain (usingfn:substringAfter()
a several times on//
and/
), but there's nothing which makes it easy to get rid of the trailing part. Maybe with a whole bunch offn:substringAfter
andc:set
in a loop, but it would make the code clumsy and not really reuseable.Well, in regex you could use
^[^/]+/+[^/]+|[^/]+$
for this:You could create a custom EL function which does exactly this:
To achieve this, first create a class like this:
and create a
/WEB-INF/functions.tld
like this:which you can import as: