• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Crazy sendRedirect() problem -- Urgent

 
jodi blair
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will get a better response to this question in the Servelets and JSP's forum. I'm moving this thread there.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic