This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Doubts on web.xml entries

 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am prepraring for SCWCD. I was going through HFSJ book yesterday and i could not follow these two points

1) HFSJ book says <load-on-startup> value can contain any non-negative number, and container loads in the order of the number given.
In the same page, it is given that it should have a value of greater than zero.
With this, I have a doubt whether we can have a <load-on-startup> value as zero, and will it be loaded before with value one?
All negavtive numbers will be ignored by container?

2) In HFSJ book, regarding <servlet-mapping> there is no clear information is given.. Servlet mapping will be choosed based upon, exact match, directory match or extension match in the order.
there were three mappings defined in web.xml
servlet one - *.do
servlet two - /fooStuff/bar
servlet three - /fooStuff/*

request uri is given as:
http://localhost:8080/MapTest/fooStuff/bar/blue.do

I though aswer is two... but answer is given as three...
There is no explanation is given in the book clearly why answer is three..
Can any one explain in detail, how servlet container matches servlet name based on url mapping?
Or can any one refer to good material on this servlet mapping alone?

Thanks & Regards,
Rizwan,
SCJA, SCJP.
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

1) from the servlet specification

The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses. If the value is a positive integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.



2)
<blockquote>quote:
In HFSJ book, regarding <servlet-mapping> there is no clear information is given.. Servlet mapping will be choosed based upon, exact match, directory match or extension match in the order.
there were three mappings defined in web.xml
servlet one - *.do
servlet two - /fooStuff/bar
servlet three - /fooStuff/*

request uri is given as:
<a href="http://localhost:8080/MapTest/fooStuff/bar/blue.do<hr rel="nofollow"></blockquote>" target="_blank">http://localhost:8080/MapTest/fooStuff/bar/blue.do

given this there is no exact match for 'fooStuff/bar/blue.do' there is a directory match which is not '/fooStuff/bar'. Because '/fooStuff/bar' does not end with an /* it is only compared to an exact match so the closest directory match is '/fooStuff/*' which is servlet three. I think that HFSJ does explain this somewhere, I would be really suprised if it didn't, but it may be later in the book, or in a side bar or bubble somewhere not entirly obvious. So reread the chapter and have a bit of a look for it. It is explained somewhere I am sure.

Mat
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Mat for your explanation. It helped to understand better.
 
Well THAT's new! Comfort me, reliable tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic