日期:2014-05-17  浏览次数:20717 次

Struts标签<html:cancel/>取消按钮处理事件

<html:cancel/>标签默认情况下点击,是会报错的。

?

要想使用此按钮可以在 struts-config.xml 中的action 增加如下相应属性:

?

<set-property property="cancellable" value="true" />

?

详细位置如下所示:

?

<action
      attribute="helloForm"
      input="/form/hello.jsp"
      name="helloForm"
      path="/hello"
      scope="request"
      type="com.zwn.struts.action.HelloAction">

     <set-property property="cancellable" value="true"/>

     
     <forward name="success" path="/form/helloSuccess.jsp" />
     <forward name="fail" path="/form/helloFail.jsp"  redirect="true"/>
?</action>
? ?

?

再在对应action里面增加对cancel按钮的处理方法:

?

?
public ActionForward execute(ActionMapping mapping, ActionForm 

form,HttpServletRequest request, HttpServletResponse response) {

              if (isCancelled(request)) { // 取消按钮处理

			return mapping.findForward("fail");

		}


		HelloForm helloForm = (HelloForm) form;
												
		return mapping.findForward("success");
	}

??

?

?

?