Академический Документы
Профессиональный Документы
Культура Документы
What is Struts
Struts Framework Features
Struts Architecture
Struts Model Component
Struts View Component
Struts Control Component
Struts Tag Libraries (HTML, Bean, Logic)
ActionForm
ActionServlet
Action ©2005 Accenture All Rights Reserved. 2
© AccentureActionMapping
2005 All Rights Reserved
Overview
Detailed in this
review:
<b>
<bean: write name=" UserContainer" property=" cart. size“ scope=" session"/>
</ b>
<br> Current Total:
<b>
$ <bean: write name=" UserContainer" format="#,## 0.00"
property=" cart. totalPrice“ scope=" session"/>
</ b>
Logic Tag Library Example <logic: iterate id=" cartItem" scope=" session" name="
UserContainer" property=" cart. items">
…
<html: link
page="/ action/ viewitemdetail? method= viewItem"
paramName=" cartItem"
paramId=" id"
paramProperty=" id">
<bean: write name=" cartItem" property=" name"/>
</ html: link>
…
</ logic: iterate>
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
application
– Handle request
– Perform business logic
Can be simple or sophisticated
– Simple action class does handle business logic by
itself
– Sophisticated ones invoke Model components
©2005 Accenture All Rights Reserved. 23
Action class functions as a Facade pattern in this case
© Accenture 2005 All Rights Reserved
Example
Action Class (cont.)
package com.jds.apps.hr.employee.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
– <controller>
– <message-resources>
©2005 Accenture All Rights Reserved. 26
– <plug-in>
© Accenture 2005 All Rights Reserved
Configuring Applications
HRS struts-config.xml file
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<!-- ========== Data Source Configuration =============================== -->
<!--
<data-sources>
<data-source>
<set-property property="autoCommit"
value="false"/>
<set-property property="description"
value="Example Data Source Configuration"/>
<set-property property="driverClass"
value="org.postgresql.Driver"/>
<set-property property="maxCount"
value="4"/>
<set-property property="minCount"
value="2"/>
©2005 Accenture All Rights Reserved.
<set-property property="password" 27
value="mypassword"/>
© Accenture 2005 All Rights Reserved
Configuring Applications
HRS struts-config.xml file (cont.)
<!-- ========== Form Bean Definitions =================================== -->
<form-beans type="org.apache.struts.action.ActionFormBean">
<form-bean name="LoginForm" type="com.jds.architecture.authenticate.LoginForm">
</form-bean>
<form-bean name="EmployeeInfoForm"
type="com.jds.apps.hr.employee.form.EmployeeInfoForm">
</form-bean>
<form-bean name="EmployeeSearchForm"
type="com.jds.apps.hr.employee.form.EmployeeSearchForm">
</form-bean>
<form-bean name="ApproversSearchForm"
type="com.jds.apps.hr.approver.form.ApproversSearchForm">
</form-bean>
<form-bean name="BlankForm" type="com.jds.architecture.beans.BlankFormBean">
</form-bean>
….
<form-bean name="SearchProjectForm"
type="com.jds.apps.hr.project.form.SearchProjectForm">
</form-bean>
<form-bean name="ProjectForm" type="com.jds.apps.hr.project.form.ProjectForm">
</form-bean> ©2005 Accenture All Rights Reserved. 28
<form-bean
© Accenture name="EmpProjectListContainForm"
2005 All Rights Reserved
Configuring Applications
HRS struts-config.xml file (cont.)
<!-- ========== Action Mapping Definitions ============================== -->
<global-forwards>
<forward name="login" path="/login.do">
</forward>
<forward name="logoff" path="/logoff.do">
</forward>
<forward name="systemError" path="/error/errorPage.jsp">
</forward>
</global-forwards>
<action-mappings>
<controller>
<!-- The "input" parameter on "action" elements is the name of a
local or global "forward" rather than a module-relative path -->
<set-property property="inputForward" value="true"/>
</controller>
</struts-config>