struts-1.3.10中的 標籤中的用法

 <action path="/prepareValidator"
                type="examples.SuccessAction">
            <forward name="success" path="/jsp/validator/Validator.jsp"/>
        </action>

        <action path="/processValidator"
                type="examples.validator.ProcessValidatorAction"
                name="validatorForm"
                scope="request"
                input="/jsp/validator/Validator.jsp"
                cancellable="true"               
                validate="true">
            <set-property property="actionId" value="validatorAction"/>
            <forward name="success" path="/jsp/validator/ValidatorResults.jsp"/>
        </action>

這是在struts-config.xml中的配置一個Action

這是對應的表單

<html:form action="validatorAction" method="get">

	<table>
	<tr><td>Byte:</td><td><html:text property="byteValue" /> -128 .. 127</td></tr>
	<tr><td>Short:</td><td><html:text property="shortValue" /> -32768 .. 32767</td></tr>
	<tr><td>Integer:</td><td><html:text property="integerValue" /> -2147483648 .. 2147483647</td></tr>
	<tr><td>Long:</td><td><html:text property="longValue" /> -9223372036854775808 .. 9223372036854775807</td></tr>
	<tr><td>Float:</td><td><html:text property="floatValue" /> 1.4E-45 .. 3.4028235E38</td></tr>
	<tr><td>Double:</td><td><html:text property="doubleValue" /> 4.9E-324 .. 1.7976931348623157E308</td></tr>
	<tr><td>Credit Card:</td><td><html:text property="creditCard" /> e.g. 4444333322221111 (no spaces) </td></tr>
	<tr><td>Date:</td><td><html:text property="date" /> mm/dd/yyyy</td></tr>
	<tr><td>Email:</td><td><html:text property="email" /></td></tr>
	<tr><td>Mask:</td><td><html:text property="mask" /> US zip code e.g. 90210</td></tr>
	<tr><td>Min Length:</td><td><html:text property="min" /> (minimum 5 characters)</td></tr>
	<tr><td>Max Length:</td><td><html:text property="max" /> (maximum 10 characters)</td></tr>
	<tr><td>Range:</td><td><html:text property="range" /> 100 .. 1000</td></tr>
	<tr><td>* Required:</td><td><html:text property="required" /></td></tr>
	</table>
	<p>These two fields must contain the same value:</p>
	<table>
	<tr><td>* Password:</td><td><html:password property="password" redisplay="false"/> (minimum 5 characters)</td></tr>
	<tr><td>* Password confirmation:</td><td><html:password property="password2"  redisplay="false"/></td></tr>
	</table>

	<hr noshade="noshade" />   
	<p>
		<html:submit>
			<bean:message key="button.submit" />
		</html:submit>
		<html:cancel/>
	</p>
</html:form>

這個表單的action是validatorAction,但是顯出的頁面確實提交到/processValidator.do,這就是set-property標籤其的作用,在<html:form/>這個標籤中,action的路徑尋找是這樣的寫的:

The URL to which this form will be submitted. This value is also used to select the ActionMapping we are assumed to be processing, from which we can identify the appropriate form bean and scope. If a value is not provided, the original URI (servletPath) for the request is used.


就是選擇ActionMapping對應的Action來處理,set-property 標籤的作用就是設置ActionMapping的ActionID屬性,讓processValidator這個Action對應到ActionMapping的ActionID屬性,所以在尋找Action路徑來處理這個Form表單的時候就是選擇ActionID爲validatorAction的Action,就是processValidator這個Action

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章