Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To Stop the execution of the Action Class

 
chandra kambham
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a "return" statement.
 
chandra kambham
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That'd be because you have code after the return.
 
chandra kambham
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My requirement is to stop the execution of code after i forward the request to another JSP.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic