participate


JavaServer Pages (JSP) and JSTL - url pattern tag and regular expression
<<   Back to Forum  |   Give us Feedback
This topic has 2 replies on 1 page.
florida41
Posts:65
Registered: 12/3/04
url pattern tag and regular expression   
May 9, 2007 5:39 PM

 
I am trying to set up my web.xml in Tomcat 4.1.3 container to go to one page if letters are entered in last part of url or go to another page if numbers are entered in the last part of a url.

For example if here is how the url would be set up where the url will go to either the all numbers location or the non numbers location:

Any number entry for last part of url which could be something like 343
http://127.0.0.1:8080/theapp/pack/weburl/343

Any non number entry for last part of url which could be something like abec
http://127.0.0.1:8080/theapp/pack/weburl/abec

My attempt below is not working because it doesnt seem to take the regular expressions. But if I manually put in letters such as: <url-pattern>/pack/weburl/ab</url-pattern> it would take me to the correct page. How does web.xml work with regular expressions inthe url-pattern tag??

<servlet>
<servlet-name>Number</servlet-name>
<servlet-class>pack.Number</servlet-class>
</servlet>
 
<servlet-mapping>
<servlet-name>Number</servlet-name>
<url-pattern>/pack/weburl/\d*</url-pattern>
</servlet-mapping>
 
<servlet>
<servlet-name>NotNumber</servlet-name>
<servlet-class>pack.NotNumber</servlet-class>
</servlet>
 
<servlet-mapping>
<servlet-name>NotNumber</servlet-name>
<url-pattern>/pack/weburl/[A-Za-z]</url-pattern>
</servlet-mapping>
 
evnafets
Posts:10,798
Registered: 29/04/03
Re: url pattern tag and regular expression   
May 9, 2007 7:02 PM (reply 1 of 2)  (In reply to original post )

 
Sorry, this pattern can't take regular expressions.

Referring to the servlet spec section 11.2 which defines these mappings


In the web application deployment descriptor, the following syntax is used to define
mappings:
? A string beginning with a ?/? character and ending with a ?/? postfix is used
for path mapping.
? A string beginning with a ?
.? prefix is used as an extension mapping.
? A string containing only the ?/? character indicates the "default" servlet of the
application. In this case the servlet path is the request URI minus the context
path and the path info is null.
? All other strings are used for exact matches only.


As an alternative, I would suggest that you match the request to a filter, and then use some logic based on request.getURI() to determine which resource to forward to from there.
 
BalusC
Posts:29,957
Registered: 26/04/06
Re: url pattern tag and regular expression   
May 9, 2007 9:50 PM (reply 2 of 2)  (In reply to #1 )

 
If you're looking for something like Apache mod_rewrite, I'd suggest you to take a look here: http://tuckey.org/urlrewrite/

Then you can configure this to redirect all numbered requests to /webapp/numberservlet and all non-numbered requests to /webapp/nonnumberservlet, which you can define in the web.xml then.
 
This topic has 2 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums