本文主要是介绍struts1.2的action参数配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<struts-config><form-beans><form-bean name="baseForm" type="jade.struts.form.BaseForm"/></form-beans><action-mappings><!-- 关注action的配置 --><action path="/customer/customer_action" //请求urlname="baseForm" //该Action绑定的ActionForm(存放请求参数)validate="false" //是否执行ActionForm中的validate方法来校对请求参数,缺省为trueinput="/error.jsp" //当Bean发生错误时返回的路径scope="request" //指定ActionForm的作用域,可选值有request和session,缺省为sessiontype="cn.com.pc.groupbuy.action.CustomerAction" //请求处理类parameter="method"> //用url参数指定处理方法。如:/user.do?method=execute将调execute方法<forward name="list" //逻辑视图名(ActionForward对象值),如:mapping.findForward("list")path="/WEB-INF/pages/customer/customer_list.jsp" //视图redirect="false"/> //是否重定向(默认值为false)</action></action-mappings>
</struts-config>
在提交页面添加隐藏域
<html:hidden property="method" value="add"/>
当提交 到上面的 action 当中后 他就自动 去找 add 这个方法执行了
还有必须在mxl 当中配置
<action path="/userOperator" type="com.rhcj.customer.struts.action.UserAction"
name="userForm"
scope="request"
parameter="method"
validate="false">
<forward name="search" path="/customer/search.jsp"></forward>
</action>
parameter="method" 这个属性
在struts-config.xml里的<action parameter="method" >就可以了
form 里 action.do?method=xxx
就可以了!
struts1 Action 配置
action元素的所有配置会被映射到ActionMapping对象中。
下面是action元素的每个属性的作用描述:
attribute在struts将JSP页面的表单对象封装成一个ActionForm对象后,会将这个ActionForm对象保存在request作用域中或者session作用域中,attribute属性就是作为key被存储到作用域中。
在JSP页面可以直接使用EL表达式去获取ActionForm对象:
${requestScope.对象名.属性}
或者
${sessionScope.对象名.属性}
这里的对象名就是attribute属性定义的值。
注意:当action元素中定义了name属性后,attribute属性的值将被忽略。
如果当前action需要用到ActionForm时,name属性是必须的,attribute属性就是非必须的。
一般情况下,attribute属性值与name属性值的值相同。
cancellable可 取的值为:true,false,yes,no。在JSP页面的表单中,<html:cancel />标签允许退出当前Action,如果cancellable属性值为真(true,yes),则一切正常。如果cancellable属性为假 (false,no),则点击cancel按钮后发生org.apache.struts.action.InvalidCancelException异常。
默认为false。
catalogThe name of a commons-chain catalog in which to look up a command to be executed as part of servicing this request. Only meaningful if "command" is also specified.
className某个实现ActionMapping类的子类的全路径名(包括包名)。可以自定义一个ActionMapping的子类。
默认为<action>元素的父节点<action-mappings>的type属性,如果未定义则默认为org.apache.struts.action.ActionMapping。
commandThe name of a commons-chain command which should be looked up and executed as part of servicing this request.
extendsThe path of the ActionConfig that this object should inherit properties from.
forward某个servlet或者jsp页面或者其他资源的相对路径。如果使用了forward属性,则当前action被触发时,会跳转到forward属性指定的资源,不会继续进行处理,当然也会忽略type属性。
<action path="/login" forward="/form/login.jsp" />
当 用户访问"/login.do"时,会forward到"/form/login.jsp"页面,Struts内部会使用 RequestDispatcher.forward()方法。这是一个很好的隐藏JSP页面的真实路径方法。可以将JSP页面放在WEB-INF目录 下,这样只能通过"*.do"或者被Action调用的形式访问。
include作用同forward属性,可以包含某个资源,内部是通过RequestDispatcher.include()方法实现。 同样会忽略type属性。
input当前action的提交页面路径(默认)或者其他资源的相对路径。使用ActionMapping.getInputForward()可以返回input属性指定的资源路径。
当FormBean的验证方法vaildate返回不为null的ActionErrors时,将返回input属性指定的路径,如果没有指定input属性,将抛出异常(java.lang.IllegalArgumentException: The path of an ForwardConfig cannot be null)
当在action元素中定义了name属性时,input属性是必须定义的。
nameFormBean的name,应该与<form-bean>元素中的name属性相同,这样才能将FormBean与当前action绑定起来。
如果有了name属性,则必须定义input属性。
attribute属性与name属性类似,但是name是必须的,attribute不是必须的。
Action是通过name属性去寻找自己的FormBean,而不是attribute属性。
parameter此 属性结合DispatchAction类使用。当parameter属性值为method,则访问链接"/userAction?method=add" 时,在继承了DispatchAction的Action类中会调用自定义的add方法。实现不同的操作,自动调用不同的业务处理方法。不用手动去写if else代码了。
具体,请参看《Struts1.X-DispatchAction类-根据请求参数实现业务分派》
path以"/"开头,不带文件扩展名的路径,Struts根据path属性来选择相应的Action处理用户的请求。比如当某个请求地址为"show.do",则path属性应该为"/show",这样才能找到合适的Action处理用户的请求。
prefix指 定填充当前 Action 关联 FormBean 时 ,要添加到请求参数名称的前缀,因此,如果请求参数名为 "username" 并且 prefix 属性被设置为 "search" ,则将对 FormBean 调用一个名为 setSearchUsername() 的方法,只有指定了 name 属性,本属性才有效
roles以逗号分割的一段role角色名,只有这些角色才能访问当前Action,其他用户访问后会抛出【org.apache.struts.chain.commands.UnauthorizedActionException】异常。
scopeFormBean的作用域,可取的值为request和session,默认为session。如果未定义name属性,则这个属性也就么意义了。
suffix作用同prefix,suffix为后缀,prefixx为前缀。
type完整的类名,包括包名,此类应该是org.apache.struts.action.Action类的子类。如果定义了forward属性或者include属性,则type属性被忽略。
unknown可取的值:true,false,yes,no。当为真时(true,yes),当前这个Action将处理所有未找到相应处理Action的请求。只能有一个Action的unknown属性为真。默认为false。
validate可取的值:true,false,yes,no。当为真时(true,yes),在进入Action处理类前,是否调用ActionForm Bean的validate()方法对表单数据进行验证。默认为true。
这篇关于struts1.2的action参数配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!