This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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

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: 19719

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: response.sendRedirect Immediately In Struts
jQuery in Action, 3rd edition