Apache Struts Framework
Apache Struts Framework
PEG Lunch-n-Learn
Nov 9, 2005
submit
start up
JSP Action
Struts-config.xml
Jar files
Place in \WEB-INF\lib
Tag Libraries
Place in \WEB-INF\taglibs
Struts-config dtd
Place in \WEB-INF
Application.properties
Default location: \WEB-INF\classes\resources
Somewhat configurable
Name can be “name”.properties
Location can be \WEB-INF\classes\”folder name”
Currently using “bundles” folder name
Contains messages for display within the
application
<Directory "C:/sites/engdev/tomcat/webapps/TicketManagement">
DirectoryIndex soComLogin.jsp
Order deny,allow
Allow from all
</Directory>
### These JkMount directives will determine what requests will be sent
### to Tomcat.
JkMount /TicketManagement/*.do ajp13
JkMount /TicketManagement/*.jsp ajp13
Web.xml file
Action servlet configuration
Servlet request mapping
Struts tag libraries configuration
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
Struts-config.xml
Location: \WEB-INF\conf
Basic configuration tags
<global-exceptions>
<form-beans>
<global-forwards>
<action-mappings>
<message-resources>
<plug-in>
Form-beans
Defines what ActionForm objects can be
created by the ActionServlet, and what to
call them.
Format:
<form-beans>
<form-bean name="inactivateContactForm"
type=“some.package.name.InactivateContactForm" />
<form-bean name="UserSelfRegistrationActionForm"
type="org.apache.struts.action.DynaActionForm">
<form-property name="userName" type="java.lang.String" />
</form-bean>
</form-beans>
Copyright © 2006 – Celeritas Technologies, LLC
Struts-config.xml (cont.)
Global-forwards
Defines ActionForward paths that are
available to all Actions in an application.
Format:
<global-forwards>
<forward name=“mergeSuccess" path="/MergeDisplay.do" />
<forward name="cancel“ path="/soCacCloseTargetPage.jsp" />
</global-forwards>
Action-mappings
Define what operations the application can
undertake.
<action-mappings>
<action path="/SelectMergeJournal"
type=“some.package.name.SelectMergeJournalAction"
name="selectMergeJournalForm"
scope="request"
validate="true"
input="/soCacMergeJournalSelectSources.jsp" >
<forward name="back" path="/StartMergeJournal.do" />
<forward name="next" path="/FinishMergeJournal.do" />
</action>
<action path="/FinishMergeJournalDisplay"
type="org.apache.struts.actions.ForwardAction"
parameter="/soCacMergeJournalFinish.jsp" />
<action-mappings>
Copyright © 2006 – Celeritas Technologies, LLC
Struts-config.xml (cont.)
Message-resources
Deploys the message bundle files needed
by the application (xyz.properties).
Default file:
\WEB-INF\classes\resources\application.properties
Format:
<message-resources key="spatial"
parameter="bundles.SpatialObjectsResourceBundle" />
<message-resources key="cac"
parameter="bundles.CacResourceBundle" />
Plug-in
Defines special resources that are available
to the Action classes.
Format:
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/conf/tiles-def.xml" />
<set-property property="definitions-parser-validate" value="true" />
<set-property property="definitions-debug" value="2" />
<set-property property="definitions-parser-details" value="2" />
</plug-in>
Web.xml setup
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/conf/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/adminModule</param-name>
<param-value>/WEB-INF/conf/struts-adminModule.xml</param-value>
</init-param>
<init-param>
<param-name>config/loginModule</param-name>
<param-value>/WEB-INF/conf/struts-loginModule.xml</param-value>
</init-param>
Struts-loginModule.xml setup
<action-mappings>
<action path="/ApplicationHome"
type="org.apache.struts.actions.ForwardAction"
parameter="/Switch.do?prefix=&page=/DataPortCart/soMainFrames.jsp" />
<action path="/Login"
type="org.apache.struts.actions.ForwardAction"
parameter="/loginModule/soComLogin.jsp" />
<action path="/Logout"
type="org.apache.struts.actions.ForwardAction"
parameter="/loginModule/soComLogout.jsp" />
<action path="/Switch"
type="org.apache.struts.actions.SwitchAction" />
</action-mappings>
Pros
Modules can be developed/modified
independently
Smaller, cleaner configuration files
Cons
Global items (forwards, exception handlers,
plug-ins) must be defined in each module
that needs access to them
Possible work-around #1
<param-name>config</param-name >
<param-value>
/WEB-INF/conf/struts-config-common.xml,
/WEB-INF/conf/struts-config.xml
</param-value>
<param-name>config/module2</param-name >
<param-value>
/WEB-INF/conf/struts-config-common.xml,
/WEB-INF/conf/struts-config-module2.xml
</param-value>
Possible work-around #2
<param-name>config</param-name >
<param-value>
/WEB-INF/conf/struts-config.xml,
/WEB-INF/conf/struts-config-module1.xml,
/WEB-INF/conf/struts-config-module2.xml
</param-value>
<action path="/userMaintenance"
type="com.celeritasworks.webfast.sec.struts.actions.UserMaintenanceAction"
name="UserMaintenanceActionForm"
scope="request"
validate="false"
input="userMaintenanceDef">
<forward name="success“ path="userMaintenanceDef" />
</action>
www.celeritas.com