wood burning stoves 2.0*
The moose likes Servlets and the fly likes url pattern in web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "url pattern in web.xml" Watch "url pattern in web.xml" New topic
Author

url pattern in web.xml

Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
I want to specify 2 url patterns for that same servlet, but not able to do so.
<servlet-mapping>
<servlet-name>HtmlFilter</servlet-name>
<url-pattern>/html/*</url-pattern>
<url-pattern>/HtmlFilter</url-pattern>
</servlet-mapping>

But, it is taking request only for /HtmlFilter, but not for /html/*.
Do i need to give two servlet-mapping and two declarations for servlet using <servlet>.
Please tell.
Duc Vo
Ranch Hand

Joined: Nov 20, 2008
Posts: 254
You'll need to declare two servlet-mapping tags i.e.


“Everything should be as simple as it is, but not simpler.” Albert Einstein
Duc Vo
Ranch Hand

Joined: Nov 20, 2008
Posts: 254
Also, why is your servlet named "filter" but it is not a Filter?
vijay dadhwal
Ranch Hand

Joined: Dec 02, 2008
Posts: 47

yes, you can provide as many as mapping you want for a servlet
mapping can be done in single mapping block like this


Vijay (SCJP)


MCA , SJCP
Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
I specified many url-patterns, but it took only one.When i wrote multiple servlet-mappings ,then it worked. Seems like we can not write multiple url-pattern in same servlet-mapping
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by vijay dadhwal:
yes, you can provide as many as mapping you want for a servlet
mapping can be done in single mapping block like this


Vijay (SCJP)


This is true, but only in Servlet Spec 2.5 and up.
Look at SRV.S.19 (Changes from Servlet 2.4):


SRV.19.0.3 Multiple Occurrences of Servlet Mappings
Previous versions of the servlet schema allows only a single url-pattern or servlet
name per servlet mapping. For servlets mapped to multiple URLs this results in
needless repetition of whole mapping clauses.
The deployment descriptor servlet-mappingType was updated to:





So..
If you're writing for containers that don't support the 2.5 spec, you'll need to create multiple servlet-mapping entries.
[ December 16, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
vijay dadhwal
Ranch Hand

Joined: Dec 02, 2008
Posts: 47

Thanks for information

Regards
vijay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: url pattern in web.xml
 
Similar Threads
Multiple url-pattern in servlet
Problem with more than one url-mapping
can I do this in servlet-mapping?
need help: .jsp to .jspf mapping
after migrate from 4.0.1 to 4.2.0, cannot load web.xml in .war/WEB-INF