You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Stephen Riek <st...@yahoo.co.uk> on 2002/12/04 00:12:47 UTC

Can Filter-mappings be defined using regular expressions?

 There's got to be a better way of writing Filter-mapping than the following, where I want to allow any URL that begins either with:
a) /Products/*  or 
b) /<2 characters>/Products/* 

---------------------->8--------------------------

<filter-mapping>
  <filter-name>ProductsFilter</filter-name>
  <url-pattern>/Products/*</url-pattern>
 </filter-mapping>

<filter-mapping>
  <filter-name>ProductsFilter</filter-name>
  <url-pattern>/en/Products/*</url-pattern>
 </filter-mapping>

 <filter-mapping>
  <filter-name>ProductsFilter</filter-name>
  <url-pattern>/de/Products/*</url-pattern>
 </filter-mapping>

 <filter-mapping>
  <filter-name>ProductsFilter</filter-name>
  <url-pattern>/fr/Products/*</url-pattern>
 </filter-mapping>

 <filter-mapping>
  <filter-name>ProductsFilter</filter-name>
  <url-pattern>/es/Products/*</url-pattern>
 </filter-mapping>

---------------------->8--------------------------

Using */Products/* doesn't necessarily do it (and I think wouldn't work anyway) since it would also collect match /SomeFolder/Another/Products which would be incorrect.

I don't mind using the above excep that it gets messy with multiple filters, and I was wondering if it could be more efficient for Tomcat written some other way.

Thanks,

Stephen.




---------------------------------
With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs

Re: Can Filter-mappings be defined using regular expressions?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 3 Dec 2002, Stephen Riek wrote:

> Date: Tue, 3 Dec 2002 23:12:47 +0000 (GMT)
> From: Stephen Riek <st...@yahoo.co.uk>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Can Filter-mappings be defined using regular expressions?
>
>
>  There's got to be a better way of writing Filter-mapping than the following, where I want to allow any URL that begins either with:
> a) /Products/*  or
> b) /<2 characters>/Products/*
>
> ---------------------->8--------------------------
>
> <filter-mapping>
>   <filter-name>ProductsFilter</filter-name>
>   <url-pattern>/Products/*</url-pattern>
>  </filter-mapping>
>
> <filter-mapping>
>   <filter-name>ProductsFilter</filter-name>
>   <url-pattern>/en/Products/*</url-pattern>
>  </filter-mapping>
>
>  <filter-mapping>
>   <filter-name>ProductsFilter</filter-name>
>   <url-pattern>/de/Products/*</url-pattern>
>  </filter-mapping>
>
>  <filter-mapping>
>   <filter-name>ProductsFilter</filter-name>
>   <url-pattern>/fr/Products/*</url-pattern>
>  </filter-mapping>
>
>  <filter-mapping>
>   <filter-name>ProductsFilter</filter-name>
>   <url-pattern>/es/Products/*</url-pattern>
>  </filter-mapping>
>
> ---------------------->8--------------------------
>
> Using */Products/* doesn't necessarily do it (and I think wouldn't work anyway) since it would also collect match /SomeFolder/Another/Products which would be incorrect.
>
> I don't mind using the above excep that it gets messy with multiple
> filters, and I was wondering if it could be more efficient for Tomcat
> written some other way.
>

An alternative strategy would be to map your filter to "/*" (so it
receives all requests) and then programmatically check the request URI in
the filter to decide whether or not to perform the redirection action.
You could use things like regular expressions, or whatever you wanted, to
make that sort of comparison.

> Thanks,
>
> Stephen.
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Can Filter-mappings be defined using regular expressions?

Posted by "Noel J. Bergman" <no...@devtech.com>.
The Servlet Specification describes allowable mappings, and doesn't describe
regex support, which means that it isn't there.  You'd have to roll your
own, which you could implement with a controlling filter.

	--- Noel


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>