wood burning stoves*
The moose likes Servlets and the fly likes Why is my sendRedirect/sendError/requestDispatcher not working?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why is my sendRedirect/sendError/requestDispatcher not working??" Watch "Why is my sendRedirect/sendError/requestDispatcher not working??" New topic
Author

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

marlon tan
Ranch Hand

Joined: Feb 18, 2001
Posts: 53
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

Joined: May 30, 2001
Posts: 328
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


Raising Flares debut album 'Ignition' out now

http://www.raisingflares.com

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is my sendRedirect/sendError/requestDispatcher not working??
 
Similar Threads
sendRedirect after flush without IllegalStateException.
package does not exist
kindly help me in redirecting....... as soon as possible
forward() and sendRedirect()
how to connect tomcat server application to sql server