Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getRequestDispatcher problem

 
Fathima Abrahams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RequestDispatcher rd = ct.getRequestDispatcher("/servlet/AccountServlet");
try this :
RequestDispatcher rd = ct.getRequestDispatcher("/AccountServlet");
 
Krishna Srinivasan
Ranch Hand
Posts: 1862
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ur code is perfect.i think some problem with ur AccountServlet.u check whether u declared correctly ...
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do you call it from the address bar ?
 
Fathima Abrahams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic