what is ForwardAction and IncludeAction in struts?
Answers were Sorted based on User's Feedback
Answer / ranjan
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:
<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
specifies a different path for the action. The parameter
attribute specifies the URL that will be forwarded to when
the specified path is accessed.
The org.apache.struts.actions.IncludeAction Class
The 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.
The org.apache.struts.actions.LocaleAction Class
The 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 and the language to
es. The /Menu.do page will be forwarded to after the new
locale has been set.
Is This Answer Correct ? | 30 Yes | 2 No |
Answer / a.kranthi kumar
ForwardAction is used forward controle from one (jsp)page to another page(jsp) by follow MVC rules.
we can use this we simply configure it in struts-cinfig.xml
file. But we no need extend any class separately.
<action-mappings>
<action path="/success.do" type="org.apache.struts.actions.ForwardAction"
parameter="/success.jsp"/>
</action-mappings>
(or)
<action path="/success" forward="success.jsp">
Is This Answer Correct ? | 10 Yes | 3 No |
Answer / ch.n.v.ganesh
The IncludeAction has the same problem that the
ForwardAction used to have .
The IncludeAction directly calls the request
dispatcher, returns a null ActionForward which bypasses the
processing of the RequestProcessor.
Unfortunately, this problem is not as easy to fix as
the ForwardAction. While the RequestProcessor does support
includes versus forwards for ActionMappings, there is no
way for an ActionForward to request an include.
The only suggestion that comes to mind is to add an
attribute to the ActionForward to request an include,
similar to the redirect attribute. The IncludeAction can
then have the same implementation as the ForwardAction, but
set an include property on the ActionForward instead. This
change would also require a new attribute to the struts-
config_1_1.dtd.
Is This Answer Correct ? | 11 Yes | 5 No |
What is Request Dispatcher and what is Request Process?
Explain about the <html:base> tag?
What is the purpose of @action annotation?
Please can you tell me ,where can we used the MVC other than web applications.
how to debug struts project in netbean ?
Why struts 1 classes are not thread safe whereas struts 2 classes are thread safe?
What is the use of forwardaction?
What do you mean by tiles in struts?
What is actioncontext?
How is the Struts framworl related to MVC2?
what are the disadvantages of MVC architecture
Difference between JSF Framework and Struts Framework.
13 Answers Accenture, BSS, IBM, TCS,