This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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.
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?
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.