Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Strangeness...

 
Scott Batchelor
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
Pavel Halas
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. This would have been better asked in the Servlets forum. Nudge. Wink.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic