| Author |
can servlet be referenced without mapping in DD like JSPs?
|
S Reddy
Ranch Hand
Joined: May 17, 2007
Posts: 45
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
|
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.
|
[My Blog]
All roads lead to JavaRanch
|
 |
S Reddy
Ranch Hand
Joined: May 17, 2007
Posts: 45
|
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
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.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
S Reddy
Ranch Hand
Joined: May 17, 2007
Posts: 45
|
|
|
Thank you Ben Souther.
|
 |
 |
|
|
subject: can servlet be referenced without mapping in DD like JSPs?
|
|
|