wood burning stoves 2.0*
The moose likes Servlets and the fly likes Question on web container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question on web container" Watch "Question on web container" New topic
Author

Question on web container

Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
Hi,
I am trying to build understanding about web application. My question is:
How do a url in browser gets translated to a specific resource on the server.

e.g
I type: http://testserver.com/MyApp/test.do

My web app root (ie MyApp) contains a file named "test.do"
Also I have a servlet mapping also which maps test.do to a servlet.

e.g
<servlet-mapping>
<servlet-name> TestServlet</servlet-name>
<url-pattern>*.do</url-pattern>
<servlet-mapping>

In above scenario:
1. Will I get TestServlet or test.do file
2. How does a web container determines which resource to serve for a request(e.g in this scenario what is logic web server uses)
3. Does the servlet resources gets priority on static resources
Louis Bros
Ranch Hand

Joined: Jun 03, 2011
Posts: 54

Hi,

You use the Deployment Descriptor for mapping the logical name (test.do) of the servlet to the fully qualified name of the servlet (com.yoursite.YourClass).


<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.yoursite.YourClass</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test.do</url-pattern>
</servlet-mapping>

In this example the name 'TestServlet' is only used within the web.xml file. It's job is to link the servlet class to the urt-pattern.

Hope that helps


OCA7
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3826

Note that the web.xml gets the priority when choosing the resource to be served. And in a case where no matching is found then it falls back to the implicit mappings provided by the container.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on web container