Monday, 1 November 2010

URL Patterns in servlet-mapping by examples

Example of working servlet mapping in web.xml
All URL patterns must begin with / (slash).

Case 1 : Match URL path /api/* Matched Matched Matched Matched Does not Matched

Note :
/api/*/path is not a valid url-pattern. /* can only be present once at the end of url-pattern.
/* will match anything after the context path and send request to matching servlet.

Case 2 : Match extension *.action Matched Matched Matched Matched Does notMatched Does notMatched

/api/*.action is a valid url-pattern.

Case 3 : Default servlet /
It matches every request if no other url-pattern defined in web.xml matches. The servlet mapped to this pattern is called the default servlet. It is used explicitly to ensure that any malformed URL is handled rather than throwing an error.

No comments:

Post a Comment