Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on web container

 
Pankaj Kumarkk
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic