Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Name

 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I am just a beginner on servlet, i need to clear one my doubt...

Why do we have servlet name in DD. Why cant we map the class name directly with the URL pattern , the idea is to protect the name of the class file from the client.....then what is need for adding the extra layer of mapping (SERVLET NAME) between the url pattern and servlet class
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because a servlet can be either a class name, or a JSP file.
 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not get this answer, could you please take some time to elaborate little more? if servlet can be either a class name or JSP that why cant they be mapped to URL-Patterns directly?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A servlet can either be a Java class or a JSP file.


or




In addition (and maybe more importantly)
You can have several servlets in service with different names and settings; all from the same class file.



You may want to give each of these two servlets their own mapping.
It would be hard to accomplish this if the name weren't abstracted from the Java class.
[ December 03, 2008: Message edited by: Ben Souther ]
 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks..I got your above explanation
 
T. N.V.Pandian
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi,
There is one more reason why we use DD.If you use class names in url then the user know about the exact path of class in server,which is normally considered as a security threat.So we map the particular url pattern to a class.Hence,the user(in client side) doesn't know about servlet path which doesnt need to him.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic