Struts

Class ActionMapping in struts-config.xml Implementation
adplus-dvertising
Previous Home Next

In order to operate successfully, our controller servlet needs to know several things about how each request URI should be mapped to an appropriate Action class. The required knowledge has been encapsulated in a Java class named ActionMapping, the most important properties are as follows:

  • type - Fully qualified Java class name of the Action implementation class used by this mapping.
  • name - The name of the form bean defined in the config file that this action will use.
  • path - The request URI path that is matched to select this mapping. See below for examples of how matching works and how to use wildcards to match multiple request URIs.
  • unknown - Set to true if this action should be configured as the default for this application, to handle all requests not handled by another action. Only one action can be defined as a default within a single application.
  • validate - Set to true if the validate method of the action associated with this mapping should be called.
  • forward - The request URI path to which control is passed when this mapping is invoked. This is an alternative to declaring a type property.
//Default mapping into struts-config.xml file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation
//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds
/struts-config_1_3.dtd">
<struts-config>
<form-beans>
 <!-- Model of your application or Beans map here -->
</form-beans>
<global-exceptions>
</global-exceptions>
<!-- Forward page map here-->
<global-forwards>
<forward name="welcome"  path="/Welcome.do"/>
</global-forwards>
<!-- Action class, ActionForward,success page,
failure page, and all the action related stuff
map here -->
<action-mappings>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>
</action-mappings>
<!-- Validator only work on form or where 
validity is required-->
<form-validation> <formset> <form name="welcomeStruts"> <field property="username" depends="required"> <msg name="required" key="error.username"/> </field> <field property="password" depends="required"> <msg name="required" key="error.password"/> </field> </form> </formset> </form-validation> <controller processorClass="org.apache .struts.tiles.TilesRequestProcessor"/> <!--ApplicationResource file map here --> <message-resources parameter="com/myapp /struts/ApplicationResource"/> <!-- ======= Tiles plugin =============--> <plug-in className="org.apache.struts.tiles.TilesPlugin" > <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" /> <set-property property="moduleAware" value="true" /> </plug-in> <!-- ========== Validator plugin ============ --> <plug-in className="org.apache.struts.validator .ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml"/> </plug-in> </struts-config>
Previous Home Next