Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

advantage of using servlet-name element in DD  RSS feed

 
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
Marshal
Posts: 37180
515
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!