• Post Reply Bookmark Topic Watch Topic
  • New Topic

URL Pettern source  RSS feed

Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

I am very confusing the url pattern syntax, and evaluation of spefic URL to a url pattern. I need answer for following queries
1.types of URL pattern, what are they
2.any rules are there in the url pettern
3. syntax errors of url pettern
4. which url will win among similar URL petterns

any link also great helpful to me.
Milind Patil
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First line of HTTP request is,

POST /status/synopsis HTTP/1.0
(Method) (Request URI) (Protocol)

Every character in a pattern must match the corresponding character in the URL path exactly, with two exceptions.
1. At the end of a pattern, '/*' matches any sequence of characters from that point forward.
2. The pattern *.extension matches any file name ending with extension.

No other wildcards are supported, and an asterisk at any other position in the pattern is not a wildcard.

The pattern <url-pattern>/</url-pattern> always matches any request that no other pattern matches

Now final thing is exact match. It means whatever coming in the request URI should match URL pattern

1. URL pattern: <url-pattern>/status/*</url-pattern>
http://example.com/examples/status/synopsis - Matches
http://example.com/examples/status/complete?date=today - Matches

http://example.com/examples/status - Does not match
http://example.com/examples/server/status - Does not match

2. URL pattern: <url-pattern>*.map</url-pattern>
http://example.com/examples/US/Oregon/Portland.map - Matches
http://example.com/examples/US/Washington/Seattle.map - Matches
http://example.com/examples/Paris.France.map - Matches
http://example.com/examples/US/Oregon/Portland.MAP - Does not match
http://example.com/examples/interface/description/mail.mapi - Does not match

[ August 19, 2008: Message edited by: Milind Patil ]
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Milind Patil,

I also got some content in the Mikalai Zaikin notes

The servlet-mapping defines a mapping between a servlet and a URL pattern.
The path used for mapping to a servlet is the request URL from the request object minus the context
path and the path parameters. The URL path mapping rules below are used in order. The first
successful match is used with no further matches attempted:
1. The container will try to find an exact match of the path of the request to the path of the servlet.
A successful match selects the servlet.
2. The container will recursively try to match the longest path-prefix. This is done by stepping down
the path tree a directory at a time, using the '/' character as a path separator. The longest
match determines the servlet selected.
3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet container will
try to match a servlet that handles requests for the extension. An extension is defined as the
part of the last segment after the last '.' character.
4. If neither of the previous three rules result in a servlet match, the container will attempt to serve
content appropriate for the resource requested. If a "default" servlet is defined for the
application, it will be used.
The container MUST use case-sensitive string comparisons for matching.
In the Web application deployment descriptor, the following syntax is used to define mappings:
-> A string beginning with a '/' character and ending with a '/*' suffix 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.

[ August 20, 2008: Message edited by: Chintu sirivennela ]
albert Jin
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Milind!
Where did you specify 'examples' of http://example.com/examples/status/synopsis in the application project?
I am looking for where to setup the application name as default like 'examples'.
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2931
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Albert,

Welcome to javaranch!

You are replying to an old thread, so you might not get an answer from the original poster. Maybe we can help you out. Are you planning to go for the certification?

Do you want to know how URL mapping works? Or where it is done? The mapping of an URL to a servlet is done in the web.xml in the <url-pattern> of the <servlet-mapping> element.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!