Transferring Control Inside and Outside the Application


Under normal circumstances, the last thing an Action does is return an ActionForward . This is used by the Controller to determine the next page to display. But the Action doesn't actually know where that is because the Controller has final responsibility for determining the forward. The same Action can be used by several different Struts actions, with different forward paths for the same returned forward mappings.

In fact, you can even forward to another Action without going to an intermediate JSP file. If the path in the struts-config.xml for the requested forward matches the URI pattern used for Action s (usually that it ends in .do ), and Struts will immediate transfer control to the Action (run the validation on the FormAction and pass control to the Action if it succeeds).

One place that the Controller can't send you is outside the current application. That's because the forwards that you define in the Struts configuration file have to be relative to the current application.

So, if you want an Action to send the user off your site, you have to do it the good old-fashioned way. That is to say, by doing a response.sendRedirect in the Action . If you do this, you return null instead of an ActionForward .

In fact, you can actually process the entire response in the Action (in other words, treat it exactly like a traditional servlet) by using the response . So, your Action can generate an HTTP error, send a GIF file, anything you want. Just remember to return that null instead of an ActionForward .



Struts Kick Start
Struts Kick Start
ISBN: 0672324725
EAN: 2147483647
Year: 2002
Pages: 177

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net