This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "response.sendRedirect Immediately In Struts" Watch "response.sendRedirect Immediately In Struts" New topic

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 14, 2005
Posts: 19973

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.
I agree. Here's the link:
subject: response.sendRedirect Immediately In Struts
It's not a secret anymore!