• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

can servlet be referenced without mapping in DD like JSPs?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet which will never be called by user, it will always called from other servlet through RequestDispatcher. I was unable to call this servlet without mapping it in web.xml, whereas I am able to forward to JSPs to by giving the full path. Is servlets are designed this way or am I doing wrong?
If servlets are designed that way what might be the purpose?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using something like ServletContext.getRequestDispatcher(java.lang.String) to get the dispatcher, try to use ServletContext.getNamedDispatcher(java.lang.String) instead. This allow you to refer to a servlet by its name.
 
S Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Christophe Verre. It is working. But, it still requires to put a <servlet> element in DD. We need not put anything in the case of JSP. Why the difference, when JSPs also are equivalent to servlets?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP isn't the equivalent to Servlets.
It's a technology that built on top of servlets and each JSP will eventually become a deployed servlet but there is a lot that needs to be done at the container level (custom class loaders etc..) to make them work.

Containers used to ship with the capability to call servlets by fully qualified name but this has been disabled in more recent versions of just about every container out there. This is in part, due to security concerns.
See your container's documentation to see if this can be turned on and to understand the risks of doing so.
 
S Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ben Souther.
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic