The ActionForward Class


The Action Class

The Action class is where the Struts framework ends and your application code begins. As previously mentioned, Action classes provide the glue between the View and Model layers and are responsible for processing specific requests. Action classes are intended to transfer data from the View layer to a specific business process in the Model layer, and then to return data from the business process to the View layer. Business logic should not be embedded in actions, because that violates the principles of MVC.

Each action is mapped to a path in the Struts configuration file. When a request with the specified path is made to the ActionServlet, the action is invoked to process the request. The following snippet illustrates how to configure an action in the Struts configuration file:

<action-mappings>   <action path="/UpdateUser"           type="com.jamesholmes.example.UpdateUserAction"/> </action-mappings>

Which URL is used to access the action depends on how ActionServlet is configured in web.xml. If ActionServlet is configured to use path mapping, the action defined in the preceding example is accessed as http://localhost:8080/MiniHR/do/UpdateUser, assuming a server of localhost running on port 8080 and an application deployed as MiniHR. If extension mapping were used to configure ActionServlet, the URL would be http://localhost:8080/MiniHR/UpdateUser.do.

When an action is called to process a request, its execute( ) method is invoked. The execute( ) method is analogous to the service( ) method in servlets. It handles all processing. Following is an example Action subclass and its execute( ) method:

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;     import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping;     public class UpdateUserAction extends Action {   public ActionForward execute(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Perform request processing here.   } }

Retrieving Values from Form Beans

Action classes are the principal location for transferring data from the View layer to the Model layer and vice versa. Form Beans are used to encapsulate the data being transferred to and from the View layer and are passed to the execute( ) method of Action classes. Action classes then retrieve values from the Form Bean and transfer the values to the Model Layer. Form Beans should not be transferred directly to the Model layer because it creates an artificial dependency on Struts. Because of this, it is important to understand how to retrieve the data stored in Form Beans. Each of the different types of Form Beans has a different mechanism for retrieving the values stored in the Form Bean and is explained here.

Standard Form Beans that subclass org.apache.struts.action.ActionForm have basic getter and setter methods that are called directly to retrieve the values from the Form Bean as shown here:

public ActionForward execute(ActionMapping mapping,   ActionForm form,   HttpServletRequest request,   HttpServletResponse response)   throws Exception {   SearchForm searchForm = (SearchForm) form;       String name = searchForm.getName();   String ssNum = searchForm.getSsNum(); }

Notice that the incoming Form Bean must be cast to its proper type before calling any getter or setter methods.

The following code sample illustrates how to access the properties of a dynamic Form Bean. Dynamic Form Beans do not have concrete getter and setter methods. Instead their values are retrieved by passing the name of a field to the get( ) method of the DynaActionForm class.

public ActionForward execute(ActionMapping mapping,   ActionForm form,   HttpServletRequest request,   HttpServletResponse response)   throws Exception {   DynaActionForm searchForm = (DynaActionForm) form;       String name = (String) searchForm.get("name");   String ssNum = (String) searchForm.get("ssNum"); }

The DynaActionForm get( ) method has a return type of Object thus fields must be cast to their proper type when being retrieved.

Lazy DynaBeans operate identically to Dynamic Form Beans: simply pass the name of the field being retrieved to the get( ) method of the LazyDynaBean class.

public ActionForward execute(ActionMapping mapping,   ActionForm form,   HttpServletRequest request,   HttpServletResponse response)   throws Exception {   LazyDynaBean searchForm = (LazyDynaBean) form;       String name = (String) searchForm.get("name");   String ssNum = (String) searchForm.get("ssNum"); } 

Customizing the Response from an Action

By default, an ActionForward should be returned from the execute( ) method of actions to direct the controller on which view should be displayed. The controller takes care of routing to the proper JSP and the JSP generates the response to the browser. There are scenarios, however, where it is necessary to customize the response generated from an action. File downloads are an example of this. Instead of forwarding to a JSP to render a page, an action can interface directly with the HTTP response and transmit the file being downloaded. To do this, an action simply has to use the HttpServletResponse object passed to Action classes' execute method( ). Additionally the action must return null from the execute( ) method to indicate to the Struts Controller that no further processing is required. Following is an example file download action:

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;     import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping;     public class DownloadAction extends Action {   public ActionForward execute(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Perform file download processing here.         return null;   } }

Notice that null is returned from the Action class instead of an ActionForward. This is a critical detail when taking control of the HTTP response directly from within the Action class.

Struts' Built-in Actions

Struts comes packaged with several built-in utility actions that provide functionality that is useful to many applications. Table 5-2 lists each of the built-in actions and their purpose.

Table 5-2: Struts' Built-in Utility Actions

Action

Description

DispatchAction

Provides a mechanism for modularizing a set of related functions into a single action, thus eliminating the need to create separate, independent actions for each function.

DownloadAction

Provides a mechanism for easing the creation of file download actions.

EventDispatchAction

Provides a mechanism for modularizing a set of related functions into a single action, thus eliminating the need to create separate, independent actions for each function.

ForwardAction

Provides a mechanism for forwarding to a specified URL.

IncludeAction

Provides a mechanism for including the contents of a specified URL.

LocaleAction

Provides a mechanism for setting a user's locale and then forwarding to a specified page.

LookupDispatchAction

Provides a mechanism for modularizing a set of related functions into a single action, thus eliminating the need to create separate, independent actions for each function.

MappingDispatchAction

Provides a mechanism for modularizing a set of related functions into a single action, thus eliminating the need to create separate, independent actions for each function.

SwitchAction

Provides a mechanism for switching between modules in a modularized Struts application.

The following sections describe each of the built-in actions in detail.

The DispatchAction Class

The org.apache.struts.actions.DispatchAction class provides a mechanism for modularizing a set of related functions into a single action, thus eliminating the need to create separate, independent actions for each function. For example, consider a set of related functions for adding a user, updating a user, and removing a user. Instead of creating an AddUserAction class, an UpdateUserAction class, and a RemoveUserAction class, by extending DispatchAction, you can create one UserAction class that has three methods: add( ), update( ), and remove( ). At run time, DispatchAction manages routing requests to the appropriate method in its subclass. DispatchAction determines which method to call based on the value of a request parameter that is passed to it from the incoming request.

To use DispatchAction, you must create a subclass from it and provide a set of methods that will be called to process requests. Additionally, you have to set up for the action an action mapping that specifies the name of a request parameter that will be used to select which method should be called for each request. Following is an example UserAction class that extends DispatchAction:

package com.jamesholmes.minihr;     import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;     import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction;     public class UserAction extends DispatchAction {   public ActionForward add(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Add user.     ...         return mapping.findForward("success");   }       public ActionForward update(ActionMapping mapping,      ActionForm form,      HttpServletRequest request,      HttpServletResponse response)      throws Exception   {      // Update user.      ...          return mapping.findForward("success");   }       public ActionForward remove(ActionMapping mapping,      ActionForm form,      HttpServletRequest request,      HttpServletResponse response)      throws Exception   {      // Remove user.      ...          return mapping.findForward("success");   } }

Notice that this class does not provide an implementation for the execute( ) method the way typical Action classes do. This is because DispatchAction provides to you an implementation of this method that manages delegating to the individual methods. In order for your DispatchAction subclass to work, you must create in the Struts configuration file an action mapping that specifies the name of a request parameter that will be used to select the method that will be called for specific requests. Following is a sample snippet that illustrates how to do this:

<action-mappings>   <action path="/User"           type="com.jamesholmes.minihr.UserAction"      parameter="function"/> </action-mappings>

The value specified with the parameter attribute of the action tag will be used as the name of a request parameter that will contain the name of a method to invoke for handling the request. Given the preceding mapping of /User to UserAction, the following URL will invoke the add( ) method (assuming the application was run on your localhost at port 8080 and the application was deployed as /MiniHR/):

http://localhost:8080/MiniHR/User.do?function=add

To invoke the remove( ) method, use the following URL:

http://localhost:8080/MiniHR/User.do?function=remove

The DownloadAction Class

The org.apache.struts.actions.DownloadAction class provides a mechanism for easing the creation of file download actions. Instead of creating an action from scratch with all of the required infrastructure code for downloading files, the DownloadAction class can be extended. DownloadAction provides all of the infrastructure code in a simple, reusable package. DownloadAction subclasses must include a getStreamInfo( ) method that returns a StreamInfo instance with details about the file to download.

package com.jamesholmes.minihr;     import java.io.File;     import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;     import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DownloadAction;     public class ReportDownloadAction extends DownloadAction {   protected StreamInfo getStreamInfo(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     String contentType = "application/vnd.ms-excel";     File file = new File("/dir1/dir2/report.xls");         return new FileStreamInfo(contentType, file);   } }

When the DownloadAction subclass, such as ReportDownloadAction in the preceding example, is invoked, it will stream the file specified in the getStreamInfo( ) method back to the browser.

The EventDispatchAction Class

The org.apache.struts.actions.EventDispatchAction class is a subclass of DispatchAction and provides a mechanism for modularizing a set of related functions into a single action, thus eliminating the need to create separate, independent actions for each function. For example, consider a set of related functions for adding a user, updating a user, and removing a user. Instead of creating an AddUserAction class, an UpdateUserAction class, and a RemoveUserAction class, by extending EventDispatchAction, you can create one UserAction class that has three methods: add( ), update( ), and remove( ). At run time, EventDispatchAction manages routing requests to the appropriate method in its subclass. EventDispatchAction determines which method to call based on the presence of a request parameter that is passed to it from the incoming request.

To use EventDispatchAction, you must create a subclass from it and provide a set of methods that will be called to process requests. Additionally, you have to set up for the action an action mapping that specifies the names of request parameters that will be used to select which method should be called for each request. Following is an example UserAction class that extends EventDispatchAction:

package com.jamesholmes.minihr;     import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;     import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.EventDispatchAction;     public class UserAction extends EventDispatchAction {   public ActionForward add(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Add user.     ...         return mapping.findForward("success");   }       public ActionForward update(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Update user.     ...         return mapping.findForward("success");   }       public ActionForward remove(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Remove user.     ...         return mapping.findForward("success");   } } 

Notice that this class does not provide an implementation for the execute( ) method the way typical Action classes do. This is because EventDispatchAction provides to you an implementation of this method that manages delegating to the individual methods. In order for your EventDispatchAction subclass to work, you must create in the Struts configuration file an action mapping that specifies the names of request parameters that will be used to select the method that will be called for specific requests. Following is a sample snippet that illustrates how to do this:

<action-mappings>   <action path="/User"           type="com.jamesholmes.minihr.UserAction"      parameter="add,update,delete=remove,default=add"/> </action-mappings>

The value specified with the parameter attribute of the action tag specifies a comma-delimited list of method names to dispatch to if a request parameter of the same name is present in the request. In the preceding example, the add( ) method will be invoked for handling the request if an "add" request parameter is sent to the action. The value of the "add" request parameter is disregarded; only the presence of the request parameter is needed. The remove( ) method will be invoked if a request parameter named "delete" is sent. The remove( ) method, instead of a delete( ) method, is invoked because of an alias of "delete". Method aliases are specified using alias=method notation, where alias is the name of the alias for a method and method is the name of the method to invoke. A default method can be specified by using an alias with the name of "default" as shown in the preceding example. Default aliases are used for scenarios where no request parameter matches the method names specified with the action tag's parameter attribute.

Given the preceding mapping of /User to UserAction, the following URL will invoke the add( ) method (assuming the application was run on your localhost at port 8080 and the application was deployed as /MiniHR/):

http://localhost:8080/MiniHR/User.do?add.x=103

To invoke the remove( ) method, use the following URL:

http://localhost:8080/MiniHR/User.do?remove=true

The ForwardAction Class

The org.apache.struts.actions.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:

<action-mappings>   <action path="/menu"           type="org.apache.struts.actions.ForwardAction"      parameter="/menu.jsp/> </action-mappings>

For each page to which you want to link, you must create an action mapping. Each action mapping uses ForwardAction, but each specifies a different path for the action. The parameter attribute specifies the URL that will be forwarded to when the specified path is accessed.

An alternative solution to using ForwardAction is to use the forward attribute of the action tag in the Struts configuration file, as shown here:

<action-mappings>   <action path="/menu"        forward="/menu.jsp"/> </action-mappings>

These two approaches effectively yield the same results.

The IncludeAction Class

The org.apache.struts.actions.IncludeAction class provides a mechanism for including the contents of a specified URL. This action behaves similarly to ForwardAction, but instead of forwarding to the specified URL, the specified URL is included. This action is useful when you want to include the contents of one page in another.

Using IncludeAction is quite easy. Just create action mapping entries in the Struts configuration file:

<action-mappings>   <action path="/menu"           type="org.apache.struts.actions.IncludeAction"      parameter="/menu.jsp/> </action-mappings>

For each page you want to include, you must create an action mapping. Each action mapping uses IncludeAction, but specifies a different path for the action. The parameter attribute specifies the URL that will be included when the specified path is accessed.

An alternative solution to using IncludeAction is to use the include attribute of the action tag in the Struts configuration file, as shown here:

<action-mappings>   <action path="/menu"        include="/menu.jsp"/> </action-mappings>

These two approaches effectively yield the same results.

The LocaleAction Class

The org.apache.struts.actions.LocaleAction class provides a mechanism for setting a user's locale and then forwarding to a specified page. This action provides a convenient mechanism for changing a user's locale. For example, consider a site that is offered in English and Spanish versions. LocaleAction can be used to offer users a way to switch between the two languages without having to change their browser settings. With LocaleAction you simply create an action mapping and then link to the action, specifying request parameters for which locale to switch to and a page to forward after the locale has been switched.

To use LocaleAction, you must create an action mapping entry for it in the Struts configuration file and then link to the action, specifying locale information and a page to forward to after the locale has been set. Following is an example of how to configure LocaleAction in the Struts configuration file:

<action-mappings>   <action path="/SwitchLocale"           type="org.apache.struts.actions.LocaleAction"/> </action-mappings>

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 (Mexico) and the language to es (Spanish). The /Menu.do page will be forwarded to after the new locale has been set.

The LookupDispatchAction Class

The org.apache.struts.actions.LookupDispatchAction class is a subclass of DispatchAction and provides a mechanism for modularizing a set of related functions into a single action, thus eliminating the need to create separate, independent actions for each function. For example, consider a set of related functions for adding a user, updating a user, and removing a user. Instead of creating an AddUserAction class, an UpdateUserAction class, and a RemoveUserAction class, by extending LookupDispatchAction, you can create one UserAction class that has three methods: add( ), update( ), and remove( ).

At run time, LookupDispatchAction manages routing requests to the appropriate method in its subclass. LookupDispatchAction determines which method to route to based on the value of a request parameter being passed to it from the incoming request. LookupDispatchAction uses the value of the request parameter to reverse-map to a property in the Struts resource bundle file (e.g., MessageResources.properties). That is, the value of the request parameter is compared against the values of properties in the resource bundle until a match is found. The key for the matching property is then used as a key to another map that maps to a method in your LookupDispatchAction subclass that will be executed.

To use LookupDispatchAction, you must create a subclass from it and provide a set of methods that will be called to process requests. The subclass must also include a getKeyMethodMap( ) method that maps methods in the class to keys in the Struts resource bundle file. Additionally, you have to set up for the action an action mapping that specifies the name of a request parameter that will be used to select which method will be called for each request. Following is an example UserAction class that extends LookupDispatchAction:

package com.jamesholmes.minihr;     import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;     import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.LookupDispatchAction;     public class UserAction extends LookupDispatchAction {   protected Map getKeyMethodMap()   {     HashMap map = new HashMap();     map.put("button.add", "add");     map.put("button.update", "update");     map.put("button.remove", "remove");         return map;   }       public ActionForward add(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Add user.     ...         return mapping.findForward("success");   }       public ActionForward update(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Update user.     ...         return mapping.finwForward("success");   }       public ActionForward remove(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Remove user.     ...         return mapping.findForward("success");   } } 

Notice that this class does not provide an implementation for the execute( ) method as other Action classes do. This is because LookupDispatchAction provides to you an implementation of this method that manages delegating to the individual methods. Notice also the implementation of the getKeyMethodMap( ) method. This method is required by LookupDispatchAction subclasses and is used to map the names of keys in the Struts resource bundle file to methods in the class. The keys' values in the bundle file are used to match against the value of the incoming request parameter specified by the parameter attribute of the action tag in the Struts configuration file.

In order for your LookupDispatchAction subclass to work, you must create in the Struts configuration file an action mapping that specifies the name of a request parameter that will be used to select the method that will be called for a specific request. Following is a sample snippet that illustrates how to do this:

<action-mappings>   <action path="/User"           type="com.jamesholmes.minihr.UserAction"      parameter="function"/> </action-mappings>

The value specified with the parameter attribute of the action tag will be used as the name of a request parameter that will contain the value of a key in the Struts resource bundle shown here:

button.add=Add User button.update=Update User button.remove=Remove User

LookupDispatchAction will use the value of the incoming request parameter to perform a reverse lookup for a key in the resource bundle. The matching key is then mapped to the appropriate method to execute based on the key-to-method mapping specified by the getKeyMethodMap( ) method.

Given the preceding mapping of /User to UserAction, the following URL will invoke the add( ) method (assuming the application was run on your localhost at port 8080 and the application was deployed as /MiniHR/):

http://localhost:8080/MiniHR/User.do?function=Add%20User

To invoke the remove( ) method, use the following URL:

http://localhost:8080/MiniHR/User.do?function=Remove%20User

The MappingDispatchAction Class

The org.apache.struts.actions.MappingDispatchAction class is a subclass of DispatchAction and provides a mechanism for modularizing a set of related functions into a single action, eliminating the need to create separate, independent actions for each function. For example, consider a set of related functions for adding a user, updating a user, and removing a user. Instead of creating an AddUserAction class, an UpdateUserAction class, and a RemoveUserAction class, by extending MappingDispatch Action, you can create one UserAction class that has three methods: add( ), update( ), and remove( ). At run time, MappingDispatchAction manages routing requests to the appropriate method in its subclass. MappingDispatchAction determines which method to route based on the value of a parameter being passed to it from an action mapping in the Struts configuration file.

To use MappingDispatchAction, you must create a subclass from it and provide a set of methods that will be called to process requests. Additionally, you must set up action mappings that specify which method will be called for each request. Following is an example UserAction class that extends MappingDispatchAction:

package com.jamesholmes.minihr;     import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;     import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.MappingDispatchAction;     public class UserAction extends MappingDispatchAction {   public ActionForward add(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Add user.     ...         return mapping.findForward("success");   }       public ActionForward update(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Update user.     ...         return mapping.findForward("success");   }       public ActionForward remove(ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response)     throws Exception   {     // Remove user.     ...         return mapping.findForward("success");   } } 

Notice that this class does not provide an implementation for the execute( ) method as other Action classes do. This is because MappingDispatchAction provides to you an implementation of this method that manages delegating to the individual function methods.

In order for your MappingDispatchAction subclass to work, you must create in the Struts configuration file action mappings that specify the method that will be called for specific requests. Following is a sample snippet that illustrates how to do this:

<action-mappings>   <action path="/AddUser"           type="com.jamesholmes.minihr.UserAction"      parameter="add"/>   <action path="/UpdateUser"           type="com.jamesholmes.minihr.UserAction"      parameter="update"/>   <action path="/RemoveUser"           type="com.jamesholmes.minihr.UserAction"      parameter="remove"/> </action-mappings>

Notice that each action mapping uses the UserAction class, but specifies a different path for the action. Each of the unique paths will be processed by the same action, but a different method will be called based on the value specified with the parameter attribute. The value specified with the parameter attribute must match the name of a method in your MappingDispatchAction subclass.

The SwitchAction Class

The org.apache.struts.actions.SwitchAction class provides a mechanism for switching between modules in a modularized Struts application. As you'll see in Chapter 9, Struts enables you to modularize your Struts application. Each module has its own set of configuration data as well as its own request processor. SwitchAction works similarly to ForwardAction, except that before forwarding to a specified resource, the action changes the currently selected module. This is useful for forwarding to JSPs outside of the current module.

Note 

Detailed information on using the Struts modules feature is found in Chapter 9.

To use SwitchAction, you must create an action mapping entry for it in the Struts configuration file and then link to the action, specifying the module to switch to and a page to forward to after the module has been switched. Following is an example of how to configure SwitchAction in the Struts configuration file:

<action-mappings>   <action path="/SwitchModule"           type="org.apache.struts.actions.SwitchAction"/> </action-mappings>

Once configured in the Struts configuration file, SwitchAction can be put to use. Simply create a link to the action and specify the module to switch to and a page to forward to afterward. The module to switch to is specified with the prefix parameter and the page to forward to afterward is specified with the page parameter. The following URL illustrates how to use the request parameters:

http://localhost:8080/MiniHR/SwitchModule.do?prefix=/Corporate&page=/Menu.do

This example URL switches to the /Corporate module, and the /Menu.do page will be forwarded to after the module has been switched.



Struts. The Complete Reference
Struts: The Complete Reference, 2nd Edition
ISBN: 0072263865
EAN: 2147483647
Year: 2004
Pages: 165
Authors: James Holmes

Similar book on Amazon
Struts 2 in Action
Struts 2 in Action
Murach's Java Servlets and JSP, 2nd Edition
Murach's Java Servlets and JSP, 2nd Edition
Jakarta Struts For Dummies
Jakarta Struts For Dummies
Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam
Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam

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