• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How container recognizes a request for servlet

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can someone tell me how a container recognizes that the incoming request is for a servlet?

Say http://localhost:8080/hello/javaranch

Here "javaranch" is the servlet class in hello directory. How does the container recognizes that javaranch is a servlet name and then checks the web.xml for the servlet class? There can be other html pages or jsps in hello directory.

So, does it check in the order of html page, jsps and then servlets or is there some thing else which I am missing?

Thanks.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The container looks for servlet and servlet-mappings in your web.xml file.
These map the class files with your URL.
 
stu ware
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben Souther,

I know that it checks the web.xml file for servlet mapping. What I would like to know is....

Suppose the url is

http://localhost:8080/hello/javaranch.html

The container recognizes that the request is for a html page.

If the request is for http://localhost:8080/hello/javaranch.jsp, the container recognizes that the request is for a jsp page.

But if the url is http://localhost:8080/hello/javaranch how does the container know that the request is for a servlet. There is nothing in the url that suggests the container to look into the web.xml file to find the mapping.

I hope I am clear.

Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not set up a test and see what happens? Seems easy enough.
 
stu ware
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tested it before. Wondering how it was working!!!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a J2EE web container receives any request, it first checks it's list of servlet mappings from web.xml. Only if the request is not found in that list does it assume it's a file and display the file. If it is found, it calls the servlet.

In high volume sites, quite often there is a layer of one or more web servers that receive the initial request and then forward the request to the app servers. In this case, there is some type of plugin to the web server that tells it which requests to respond to and which to pass on to the application server. In this case, the data in web.xml is passed on to the web server in some manner (e.g. put in a config file and copied to the web server).
 
stu ware
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Merrill Higginson,

Awesome!!! You are right.

I wrote a sample test case with one html page and one servlet.

rootdit/first/hi.html is my html page.

Then I created a servlet by name "hi.html" and accessed it as

http://localhost:8080/first/hi.html


I got the output from the servlet instead of the html page.

I got my doubt clarified.

Thanks a lot to all of you.
 
stu ware
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Merrill Higginson,

Awesome!!! You are right.

I wrote a sample test case with one html page and one servlet.

rootdit/first/hi.html is my html page.

Then I created a servlet by name "hi.html" and accessed it as

http://localhost:8080/first/hi.html


I got the output from the servlet instead of the html page.

I got my doubt clarified.

Thanks a lot to all of you.
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank for both of you ( vasu & Merrill )...it was a nice topic.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Harish",

You have already been warned on on a previous occasion to change your display name to conform to JavaRanch standards.

This is not optional! Accounts with invalid display names are closed.

Take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

bear
Forum Bartender
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic