aspose file tools*
The moose likes Beginning Java and the fly likes Java Strangeness... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Strangeness..." Watch "Java Strangeness..." New topic
Author

Java Strangeness...

Scott Batchelor
Greenhorn

Joined: Jul 07, 2003
Posts: 11
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

Joined: Jan 10, 2002
Posts: 60079
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pavel Halas
Ranch Hand

Joined: Jul 05, 2003
Posts: 35
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

Joined: Jan 10, 2002
Posts: 60079
    
  65

P.S. This would have been better asked in the Servlets forum. Nudge. Wink.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60079
    
  65

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Strangeness...
 
Similar Threads
How to tell navigator to redirect to another url with javascript
Redirecting the req to another server ?
submiting the output in same page
How do you pass a string from servlet to jsp if jsp is on another server?
Java Strangeness...