• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getRequestDispatcher problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RequestDispatcher rd = ct.getRequestDispatcher("/servlet/AccountServlet");
try this :
RequestDispatcher rd = ct.getRequestDispatcher("/AccountServlet");
 
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ur code is perfect.i think some problem with ur AccountServlet.u check whether u declared correctly ...
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic