aspose file tools*
The moose likes Servlets and the fly likes Servlet Mapping vs Static resource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Mapping vs Static resource" Watch "Servlet Mapping vs Static resource" New topic

Servlet Mapping vs Static resource

Devendra Inamdar

Joined: Mar 25, 2006
Posts: 5
Hi Everyone,
I have a static resource which is defined as webapps/myApp/home/index.html and I have defined mapping of a servlet in the same web app with URL pattern as "/home/index.html".
e.g. <servlet-mapping>
If a URL http://host ort/myApp/home/index.html is entered through browser, will it get the static resource index.html or invoke the servlet xyz?

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Have you tried it?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
mohan kumar r
Ranch Hand

Joined: Jan 19, 2006
Posts: 38
it will invoke the servet xyz

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

That the container will choose the servlet-mapping over the static file is the basis for a common work-around for creating a "Welcome File" servlet.

Some containers (older versions of Tomcat) wouldn't allow you to use a servlet as the welcome file. By creating a mapping for, say.. "index.html", putting a blank index.html page on the server and then setting "index.html" as the welcome file, you're able to use a servlet as your intro page.
I agree. Here's the link:
subject: Servlet Mapping vs Static resource
Similar Threads
url-mapping and directory
mapping the root directory servlet for your webapp
Doubt regarding how to specify servlet mapping URL patterns in web.xml
How to run servlet on Tomcat
Web.xml - ByPass security