Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

advantage of using servlet-name element in DD

 
Hariom Tiwari
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My undersatnding says that we use <servlet-name> to tie a <servlet> elemet to a specific <servlet-mapping> element.e.g.

<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>myservlet.class</servlet-class>
<servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/myservlet</url-pattern>
<servlet-mapping>

My concern is why can't we use something like

<servlet>
<url-pattern>/myservlet</url-pattern>
<servlet-class>myservlet.class</servlet-class>
<servlet>

after all <servlet-name> is being used internally.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Servlet API is designed for flexibility and security. The dreaded Invoker servlet was designed to let you use the class name directly - it has been shown to be a BAD IDEA.

Just learn to use the deployment descriptor correctly, you will be glad in the long run. Incidently, all classes used in servlets should be in packages to avoid annoying error reports and ensure portablility.

Bill
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 35762
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hariom,
A servlet definition can have other attributes. Initialization parameters are a common example. If multiple mappings are defined for the same servlet, this would result in the repeated XML without using the servlet-name.
 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!