This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Struts and the fly likes How To Stop the execution of the Action Class 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 » Frameworks » Struts
Bookmark "How To Stop the execution of the Action Class" Watch "How To Stop the execution of the Action Class" New topic
Author

How To Stop the execution of the Action Class

chandra kambham
Ranch Hand

Joined: Jun 09, 2008
Posts: 74
Hi,

I am using an Struts action class, in which based on some condition i am forwarding the request to another JSP using the RequestDispatcher.forward().

But the code after this forward statement also getting executed...

Ex:

request.getRequestDispatcher("/XssValidator.jsp").include(httpServletRequest, httpServletResponse);
System.out.println("After Dispatching");

But i don't want the execution of code after the forward has happened.

please help me on how to implement this..

Many Thanks.
K.Chandra
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Use a "return" statement.
chandra kambham
Ranch Hand

Joined: Jun 09, 2008
Posts: 74
Can you explain me with an example of doing this..
I have written a return statement before the System.out.println("After Dispatching"); and it's compiling as this will be the unreachable code...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That'd be because you have code after the return.
chandra kambham
Ranch Hand

Joined: Jun 09, 2008
Posts: 74
My requirement is to stop the execution of code after i forward the request to another JSP.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

chandra kambham wrote:My requirement is to stop the execution of code after i forward the request to another JSP.

And that's a solution, after forwarding a request to a JSP, your code will no longer execute !!


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How To Stop the execution of the Action Class
 
Similar Threads
Struts2 key attribute
how to call servlet from struct action class
passing value from one action to another
forwarding between action classes
Refresh parent window without closing popup with struts validation