• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is servlet-name really needed? Very Interesting Doubt

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friends,
I was wondering why this <servlet-name> element in web.xml is needed?

CASE 1 :



This can be written as

CASE 2 :

<servlet>
<servlet-class> try_examples.Temp1</servlet-class>
<url-pattern>/login.html</url-pattern>
</servlet>

I know Case 2 is not correct according to the schema of web.xml but practically why case 2 is incorrect?

Can you list few advantages of case 1 over case 2. please let me know if case 2 is conceptually incorrect (practically) ?
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sandeep,
I am not sure if this will help you or not. But this is what I have to say regarding your doubt:

<servlet>
<servlet-class> try_examples.Temp1</servlet-class>
<url-pattern>/login.html</url-pattern>
</servlet>

If we use it the way given above, then how will we be able to refer to the servlet in other parts of DD. As per definition, <servlet-name> defines the canonical name of the servlet, used to reference the servlet definition elsewhere in the deployment descriptor.
One case where <servlet- name> is used to refer to the servlet is in the <filter-mapping> element of DD. <filter-mapping> element take a <servlet-name> element to allow the filter to be mapped to an individual Servlet using its logical name.

Thanks,
Rancy
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also consider getNamedDispatcher()
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answers. Actually i am not aware of filters but your answer makes sense.. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic