This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher doesn't work  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
getServletContext().getRequestDispatcher("/FooServlet?item=5");
Depending on how you've configured tomcat you may also try this:
getServletContext().getRequestDispatcher("/servlet/FooServlet?item=5");
And, if FooServlet is in a package, but doesn't have an alias it will look something like this:
getServletContext().getRequestDispatcher("/servlet/packagename.subdir.FooServlet?item=5");
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!
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!