• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Why is my sendRedirect/sendError/requestDispatcher not working??

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using TOmcat 4.0 as my web server. I've placed my Servlet inside webapps/examples/Web-INF/classes directory.
Here is the code snippet of my servlet:

public class ResponseRedirect
extends HttpServlet {
...
public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();
//res.sendRedirect("greetings.html"); <-- not working even if greetings.html is inside the same directory as request URI
//res.sendRedirect("/greetings.html"); <-- not working even if greetings.html is in webapp directory
//res.sendError(res.SC_NOT_FOUND); <-- not working.
// If two lines below are used, getWriter above is commented.
// Code below is not working either
//RequestDispatcher rd = getServletContext().
getRequestDispatcher("/examples/servlet/HelloWorld");
//rd.forward(req,res);
} // doGet
...
}
I know I've tried that using JavaWebServer and it was working fine. How come it's not working in Tomcat?
Thank you very much for the help.
[This message has been edited by marlon tan (edited October 13, 2001).]
 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
You say that it's not working but you haven't given us any error messages to work with.
Do you get an IllegalStateException after this line?

If so its because you have uncommitted output in the buffer. According to the 2.2 specs - check with the 2.3 - before the target's service() method is called using the forward() method of the RequestDispatcher, the buffer must be reset.
Bye,

------------------
Terry Doyle
Sun Certified Programmer for Java 2 Platform
 
Yes, my master! Here is the tiny ad you asked for:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!