This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes RequestDispatcher doesn't work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher doesn Watch "RequestDispatcher doesn New topic

RequestDispatcher doesn't work

einat hasenfratz

Joined: Oct 15, 2003
Posts: 1
I've tried using the getRequestDispatcher() method
The code I am using :
RequestDispatcher dispatcher =getServletContext().getRequestDispatcher("/newer/FooServlet?item=5");
dispatcher.forward(request, response);
but I keep getting an error: The requested resource (/FooServlet) is not available.
can anyone help me?
Jon Wilson

Joined: Oct 15, 2003
Posts: 14
Is your context name "newer"? If so, keep in mind that the request dispatcher is already referencing things from within its context. If "newer" is a different servlet context, then you must use sendRedirect rather than a RequestDispatcher.
Try the following instead of what you were using:
Depending on how you've configured tomcat you may also try this:
And, if FooServlet is in a package, but doesn't have an alias it will look something like this:
Another thing to try is removing the query string("?item=5"). You could set this in a request attribute prior to forwarding the request.
Also, verify that your class is indeed in /usr/local/tomcat/webapps/newer/WEB-INF/classes or in the lib directory for jars.
I hope that helps!

Mensa member, Certified bartender, Created the Internet (along with Al Gore), Speak 9 languages fluently (this includes pig latin), Spelling Bee Winner, 8th Grade Math Award, Can hold breath under water for more than 2 minutes
subject: RequestDispatcher doesn't work
It's not a secret anymore!