Saturday, December 18, 2010

ForwardAction, IncludeAction and LocaleAction in struts


The org.apache.struts.actions.ForwardAction Class
The ForwardAction class provides a mechanism for forwarding 
to a specified URL. As explained earlier, in an MVC Web 
application, all requests to the application are supposed 
to flow through the Controller servlet. This ensures that 
the Controller layer of the application has an opportunity 
to prepare any resources that may be needed to handle the 
request (i.e., selecting the correct module and so on). 
ForwardAction is provided as a simple utility action that 
can be used for scenarios in which you simply want to link 
to a JSP page. Of course, linking directly to the JSP would 
be a violation of the MVC principles because all requests 
are supposed to be routed through the Controller. 
ForwardAction can be used to create links to JSPs so that 
you don’t have to create an action whose only 
responsibility is to forward a request every time you want 
to link to a JSP. With ForwardAction, you simply create an 
action mapping in the Struts configuration file and specify 
the location to which the action will forward.

To use ForwardAction, simply create action mapping entries 
in the Struts configuration file, as shown next:


  


Once configured in the Struts configuration file, 
LocaleAction can be put to use. Simply create a link to the 
action and specify the locale settings that will be set and 
a page to forward to. Locale settings are specified with 
two request parameters: language and country. The page to 
forward to after setting the locale is specified with the 
page request parameter. The following URL illustrates how 
to use the request parameters:

http://localhost:8080/MiniHR/SwitchLocale.do?
country=MX&language=es&page=/Menu.do 

This example URL sets the country to MX and the language to 
es. The /Menu.do page will be forwarded to after the new 
locale has been set.
Cheers,
Happy Coding :-)

No comments: