Close
My cartSubtotal:CAD$ 0.00
- My cart's content
- Billing address
- Payment method
- Confirm order
struts-config.xml
. Struts framework creates ActionMapping
object from <ActionMapping>
configuration element of struts-config.xml
file<action-mappings>
<action path="/submit"
type="submit.SubmitAction"
name="submitForm"
input="/submit.jsp"
scope="request"
validate="true">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/error.jsp"/>
</action>
</action-mappings>
execute()
method of Action class the business logic is executed.public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception ;
execute()
method of Action class:ActionForward
objectprocess()
method of the RequestProcessor uses the template method design pattern. Struts also implement the following J2EE design patterns.<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/struts-config.xml,
/WEB-INF/struts-admin.xml,
/WEB-INF/struts-config-forms.xml
</param-value>
</init-param>
.....<servlet>
What is the directory structure of Struts application?The directory structure of Struts application :
execute()
method of an Action class.execute()
method – Because DispatchAction class itself provides execute()
method.IncludeAction
only if the action is going to be included by another action or jsp. Use ForwardAction
to forward a request to another resource in your application, such as a Servlet that already does business logic processing or even another JSP page.<action>
element has <forward>
declaration with same name as global forward?<action>
element’s <forward>
takes precendence.ActionForm
that allows the creation of form beans with dynamic sets of properties (configured in configuration file), without requiring the developer to create a Java class for each type of form bean.DynaActionForm
instead of a custom subclass of ActionForm is relatively straightforward. You need to make changes in two places:<form-bean>
to be an org.apache.struts.action.DynaActionForm
instead of some subclass of ActionForm
<form-bean name="loginForm"type="org.apache.struts.action.DynaActionForm" >
<form-property name="userName" type="java.lang.String"/>
<form-property name="password" type="java.lang.String" />
</form-bean>
<bean:message key="prompt.customer.firstname"/>
<bean:write name="customer" property="firstName"/>
<logic:iterate>
repeats the nested body content of this tag over a specified collection.<table border=1>
<logic:iterate id="customer" name="customers">
<tr>
<td><bean:write name="customer" property="firstName"/></td>
<td><bean:write name="customer" property="lastName"/></td>
<td><bean:write name="customer" property="address"/></td>
</tr>
</logic:iterate>
</table>
<global-exceptions>
handling tags in your struts-config.xml
or define the exception handling tags within <action></action>
tag. It works well when custom page needed when error occurs. This approach applies only to exceptions thrown by Actions.<global-exceptions>
<exception key="some.key"
type="java.lang.NullPointerException"
path="/WEB-INF/errors/null.jsp"/>
</global-exceptions>
<exception key="some.key"
type="package.SomeException"
path="/WEB-INF/somepage.jsp"/>
ActionForm
represents an HTML form that the user interacts with over one or more pages. You will provide properties to hold the state of the form with getters and setters to access them. Whereas, using DynaActionForm
there is no need of providing properties to hold the state. Instead these properties and their type are declared in the struts-config.xml
DynaActionForm
bloats up the Struts config file with the xml based definition. This gets annoying as the Struts Config file grow larger.DynaActionForm
is not strongly typed as the ActionForm. This means there is no compile time checking for the form fields. Detecting them at runtime is painful and makes you go through redeployment.DynaActionForm
, the property access is no different than using request.getParameter( .. ).DynaActionForm
construction at runtime requires a lot of Java Reflection (Introspection) machinery that can be avoided.
Dispatch Action
|
LookupDispatchAction
|
It’s a parent class of LookupDispatchAction
|
Subclass of Dispatch Action
|
DispatchAction provides a mechanism for grouping a set of related functions into a single action, thus eliminating the need to create separate actions for each function.
|
An abstract Action that dispatches to the subclass mapped executes method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping.
|
If not using Internalization functionality then dispatch action is more useful.
|
Lookup Dispatch Action is useful when we are using Internalization functionality
|
DispatchAction selects the method to execute depending on the request parameter value which is configured in the xml file.
|
LookupDispatchAction looks into the resource bundle file and find out the corresponding key name. We can map this key name to a method name by overriding the getKeyMethodMap() method.
![]() |
DispatchAction is not useful for I18N
|
LookupDispatchAction is used for I18N
|
- Copyright © 2025 My Code Snapshots -Metrominimalist- Powered by Blogger - Designed by Suresh Rohan -