• 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

Java Strangeness...

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok here is a scenario I am seeing. I am debugging my app and I am using this block of code to do a redirect:
try {
response.sendRedirect(url);
LOG.debug("Redirect URL = " + url);
} catch (IOException e) {
//
}
When I step throught his code it actually hit the line: response.sendRedirect(url);
And the url variable is correct in the logs.
But it doesnt send the app anywhere just continues on.
Any thoughts.
I hope this isnt to vague but I am stumped as to what could be causing this.
Scott
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The sendRedirect method actually doesn't perform the redirect in-line. What it does is to set up the headers on the response to instruct the user agent (usually a browser) to initiate a new request using the header information.
So you won't see anything happen until after your servlet completes and the response is sent back to the browser.
hth,
bear
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I give you a good advice. Never use empty catch block. You're going to tear your hair one day...
This is MUCH better:
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. This would have been better asked in the Servlets forum. Nudge. Wink.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, to address the exception issue, here's the idiom I use all over the code:

If an exception is thrown, you rarely want to eat it and just move on -- even if you have logged it. That's the purpose of the ServletException and why it can wrap a root cause exception (in this case the IOE).
hth,
bear
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic