| dispatchAction (dispatchAtion) | mappingDispatchAction (DispatchAction ) | resetAction (action ) |
|
|
提交不同参数的action |
| ||
Jsp页面 | <a href=" testDispatch.do ?methodName=add">分发的Action_添加</a> | <a href="testMapping_add.do"> MappingDispatchAction_添加</a> | <a href="testReset.do ?task=delete&userid=1">删除的操作</a> |
|
struts-config.xml | action中加入 parameter="methodname" | 每个不同的参数都对应一个action,并且对应action要设置parameter的值,path也要修改: path="/testMapping_add" parameter="add" |
不做特别的修改 |
|
Action | 将execute改为目标方法如此处的add | 将execute改为目标方法如此处的add | 接收的action都在execute执行,通过task接收的不同参数而分别执行 |
|
ActionForm |
|
| 设置task属性 |
|
1. 通过加载Strut1.3框架
2. 通过new —>other àwebStruts新建所需要的actionForm、action和jsp页面
3. 注意点:
A.建action:input这个参数是指actionForm中validate验证失败标志时所应该转向的页面
B.建Forward:succ是action中执行成功时的标识,由execute中的mapping通过findForward方法找到这个succ标识所指向的页面success.jsp,从而实现成功页面的跳转
C.在jsp页面中通过form标识提交的时候,action的值要与Struts-congfig.xml中的path一致
D.JSP页面中使用ActionForm标签
首先,导入标签库
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
然后,编写jsp页面
<!--show the error message of actionForm-->
<!-- 本页面的action的值要与对应的struts-config.xml中的action的Path值一致 -->
<html:form action="/testResetaction" style="form1">
textfield:<html:text property="username"></html:text><font color="red"><html:errors property="空信息"/></font>
<!-- 这里的errors property的值应设为对应的actionForm中ActionError添加时设置的错误名称 -->
<br><br>
<br><br>
sex:
<!-- 本页面的property的值要与对应的actonForm中的属性名称一致 -->
<html:radio property="usersex" value="1">Nan</html:radio>
<html:radio property="usersex" value="0">Nv</html:radio>
<br><br>
<html:submit value="submit"></html:submit>
</html:form>