• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Crazy sendRedirect() problem -- Urgent

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic