在项目中有一个新增客户信息的的功能:
1、在进入添加页面:add.jsp页面之前,要调用一个add_init.do来获取省份信息列表以供在add.jsp进行选择。
2、add页面填写完成以后,提交给addCustomer.do来进行数据库的操作,
在提交之前,要进行一次表单验证,用了STRUTS2的validation。
<!-- 客户添加初始化 --> <action name="customer_init" class="cn.rf.hz.parkassist.customer.action.AddAction" method="init"> <interceptor-ref name="chain" /> <interceptor-ref name="basicStack" /> <result name="no_login">/parkassist/admin/login.jsp</result> <result name="init">/parkassist/customer/add.jsp</result> <interceptor-ref name="store"> <param name="operationMode">RETRIEVE</param> </interceptor-ref> </action> <!-- 客户添加 --> <action name="customer_add" class="cn.rf.hz.parkassist.customer.action.AddAction" method="addCustomer"> <interceptor-ref name="chain" /> <interceptor-ref name="basicStack" /> <!-- 动态设置savePath的属性值 --> <param name="savePath">upload/selfPic/</param> <result name="success" type="redirectAction">customer_search</result> <result name="failure">/parkassist/customer/add.jsp</result> <result name="no_login">/parkassist/admin/login.jsp</result> <result name="input" type="chain"> <param name="actionName">customer_init</param> <param name="namespace">/customer_action</param> </result> <interceptor-ref name="fileUpload"> <!-- 文件过滤 --> <param name="allowedTypes">image/png,image/gif,image/jpeg</param> <!-- 文件大小, 以字节为单位 --> <param name="maximumSize">1025956</param> </interceptor-ref> <interceptor-ref name="store"> <param name="operationMode">STORE</param> </interceptor-ref> <!-- 默认拦截器必须放在fileUpload之后,否则无效 --> <interceptor-ref name="defaultStack" /> </action>
弄了3个小时,总算弄出来了。
http://struts.apache.org/release/2.1.x/docs/message-store-interceptor.html
<action name="submitApplication" ....> <interceptor-ref name="store"> <param name="operationMode">STORE</param> </interceptor-ref> <interceptor-ref name="defaultStack" /> <result name="input" type="redirect">applicationFailed.action</result> <result type="dispatcher">applicationSuccess.jsp</result> </action> <action name="applicationFailed" ....> <interceptor-ref name="store"> <param name="operationMode">RETRIEVE</param> </interceptor-ref> <result>applicationFailed.jsp</result> </action>
struts2的validate在使用过程中的一个问题
时间: 2024-10-10 18:13:32