This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
marlon tan
Ranch Hand
Posts: 53
  • 0
  • 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).]
 
Terence Doyle
Ranch Hand
Posts: 328
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic