wood burning stoves 2.0*
The moose likes Struts and the fly likes response.sendRedirect Immediately In Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "response.sendRedirect Immediately In Struts" Watch "response.sendRedirect Immediately In Struts" New topic
Author

response.sendRedirect Immediately In Struts

James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
I have some code where in certain cases I need to response.sendRedirect to another site.

The problem is...the response.sendRedirect is not immediate. In other words:



...the updateCount is still called bc the response.sendRedirect is not immediate.

If I have a "return" statement right after the response.sendRedirect my code won't compile because "This method must return a result of type ActionForward".

Sure...I could just move all the rest of the code in the page into an else block after the if statement, but isn't there a way to return immediately after the response.sendRedirect in struts?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Yes, use Java's "return" statement.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Of course those statements are called. Your code is written in Java, and the rules of Java say that after one statement is completed, the next statement is executed. There aren't any exceptions for methods like sendRedirect.

So like David says, use a return statement. Or write an if-else statement to control what code is run.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: response.sendRedirect Immediately In Struts