wood burning stoves*
The moose likes Servlets and the fly likes getRequestDispatcher problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getRequestDispatcher problem" Watch "getRequestDispatcher problem" New topic
Author

getRequestDispatcher problem

Fathima Abrahams
Greenhorn

Joined: Dec 08, 2003
Posts: 4
I am running a servlet LoginServlet that calls another servlet, AccountServlet. Tomcat is unable to find the called servlet: AccountServlet when I call it from within LoginServlet. AccountServlet runs properly when I run it from the address bar, but as soon as I attempt to obtain a RequestDispatcher object using AccountServlet I get the unable to find Account Servlet error. Here is the code that is giving me problems:
ServletContext ct = getServletContext();
RequestDispatcher rd = ct.getRequestDispatcher("/servlet/AccountServlet");
rd.forward( req, res );
Everything else is fine but I cant seem to get AccountServlet running. Should I specify a more specific path in my getRequestDispatcher method call?
Amol Takate
Greenhorn

Joined: Sep 20, 2003
Posts: 15
RequestDispatcher rd = ct.getRequestDispatcher("/servlet/AccountServlet");
try this :
RequestDispatcher rd = ct.getRequestDispatcher("/AccountServlet");
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

ur code is perfect.i think some problem with ur AccountServlet.u check whether u declared correctly ...


Krishna Srinivasan
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

how do you call it from the address bar ?
Fathima Abrahams
Greenhorn

Joined: Dec 08, 2003
Posts: 4
I have not tried calling AccountServlet from the address bar yet. None of my servlets are in packages. My directory structure is as follows:
webapps/bankingApp/web-inf/classes.
AccountServlet and LoginServlet reside in the classes directory.
The servlet is declared in my deployment descriptor is as follows:
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>AccountServlet</servlet-name>
<servlet-class>AccountServlet</servlet-class>
</servlet>
I have tried calling AccountServlet using
RequestDispatcher rd = ct.getRequestDispatcher("/AccountServlet");
but still no luck.
Thanks for all your responses.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

In your first post, you said " AccountServlet runs properly when I run it from the address bar,", but never mind...

* WEB-INF , not web-inf (there's a big difference)

* please package your servlets

* read about servlet mappings, and USE them (please). read this entire FAQ
Also in that document, you'll read about the invoker servlet (and why it's evil).
[ December 09, 2003: Message edited by: Mike Curwen ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getRequestDispatcher problem