struts-config.xml 下的action-mapping元素
在本例中action先接受SavaAction的请求,并映射到struts.sample.cap5.sample1.action.SaveAction,同时将CheckForm内容一并传送。
<action-mappings >
<action
attribute="CheckForm"
input="/user.jsp"
name="CheckForm"
path="/SavaAction"
scope="request"
type="struts.sample.cap5.sample1.action.SaveAction"
validate="true">
<forward name="success" path="/user.jsp" />
</action>
</action-mappings>
在action-mapping元素下可以定义0个或1个以上的action元素。每个action元素接受path属性定义的请求,并映射到type属性所定义的具体的Action对象。在映射过程中,将name属性定义的ActionForm内容一并传送过来。
input属性表示请求验证失败之后返回的页面
validate属性指定了是否需要ActionForm验证
forward属性制定了页面成功或失败之后跳转的页面
parameter属性指定了传送方式
scope实行指定了作用范围,常用值session 和 request
完整的struts-config.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<!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-sources />
<form-beans >
<form-bean name="CheckForm" type="struts.sample.cap5.sample1.form.CheckForm" />
<form-bean name="CheckForm2" type="org.apache.struts.validator.DynaValidatorActionForm">
<form-property name="userName" type="java.lang.String" />
<form-property name="age" type="int" />
<form-property name="email" type="java.lang.String" />
<form-property name="passWord" type="java.lang.String" />
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="CheckForm"
input="/user.jsp"
name="CheckForm"
path="/SavaAction"
scope="request"
type="struts.sample.cap5.sample1.action.SaveAction"
validate="true">
<forward name="success" path="/user.jsp" />
</action>
</action-mappings>
<message-resources parameter="resources.application" />
<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>