Friday, June 23, 2006

Struts - Forward Action Vs Direct JSP call

A recent developer asked me why should one use ForwardAction, when one can directly give a link to a separate JSP directly.

The reason is: When we use ForwardAction, the ActionServlet in Struts intercepts the request and provides appropriate attributes such as Message Resource Bundles and also FormBeans.
If we directly give a reference to a JSP page, then the behavior of the Struts tags may become unpredictable.

Another reason when ForwardAction would be necessary is when direct access to JSP files are prevented from direct access by using the "security-constraint" tag in web.xml.