I'm having this problem trying to redirect my servlet to another url. When I click an image on a form, it posts it, then saves info after which I call the response.sendRedirect method. It works up to the redirect then does nothing, no error or anything! When I look at the logs, it shows that the init() method never happened. I tried redirecting to another class, in case you couldn't redirect to the same class, but this gave the same results! What I was hoping you could help me with is just some suggestions as to what could be happening because I am honestly out of ideas! Thanks for any ideas! PS: the url works on its own
i don't think response.redirect() will work if you've written data to the output stream.
Is this the case maybe? ps. If you servlet is compiled from a JSP, even a blank space in the JSP can result in the servlet opening and setting the response headers, which then means you can't redirect.
Originally posted by Mike Curwen: i don't think response.redirect() will work if you've written data to the output stream.
The Servlet spec says (v2.2: 6.3) that the redirect method should work as long as the response has not yet been committed. With the default JSP buffer size of 8kb, you should be able to successfully redirect if you generated less than 8kb worth of HTML. (The redirect will clear the buffer though, losing everything you've generated). - Peter