In the following code from the book headfirst jsp and servlets
Basically we are using a servlet-name to refer to the java class and than mapping that name to the url pattern which the client will see
So My question is cant we directly map the class to the url .
some what like
Class needs to be the fully qualified package plus class name so the servlet container can find it. Classes used in servlets MUST be in packages to avoid all sorts of problems.
Way back at the beginning of the servlet API it was thought that it would be cool to allow for directly naming a servlet class in the URL. Thus we got the Invoker servlet.
These days everybody recognizes that this was a really really really bad idea since it prevented use of the full servlet API.
The objective of this kind of mapping is
1 . The actual servlet name and location available on the server would not be visible to the user , which would be necessary for security .
2 . Than there would be an internal name for that servlet know among the deployers which would be Chapter1 Servlet in the above case as specified.
3. The class name would be specific to developers to be known among them .
4. Maintainence would be definately easy as we would not have to keep on changing each and every JSPs if the servlet name or anything else changes , we can directly change the web.xml mapping which is basically global mapping of servlets for that particular application .
This is the basic understanding i got from Head first .
William Brogden
,
Author and all-around good cowpoke
Also note that the "name" of a servlet class includes the package and may therefore be quite long.
Would your really like to type the whole com.mysite.stuff.thingee.BigServletWork name when mapping lets you call it "Work"? How prone to error is that?
Not even getting into the security hazard of having your whole package structure exposed everywhere.
William Brogden wrote:
Not even getting into the security hazard of having your whole package structure exposed everywhere.
I don't understand how that why separating servlet-class and url-pattern can prevent a security hazard. The 2 <servlet> and <servlet-mapping> are in the same document, any author of web.xml will be able to see the whole class name.
Would you mind explain further? Thanks
William Brogden
,
Author and all-around good cowpoke