File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can servlet be referenced without mapping in DD like JSPs?

 
S Reddy
Ranch Hand
Posts: 45
  • 0
  • 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?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • 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
  • 0
  • 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?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ben Souther.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic