html:cancel按钮的作用,cancel按钮,取消按钮

struts判断标签

html:cancel
html:cancel标签生成一个取消按钮。当点击该按钮后action servlet会绕过相应的form bean的validate()方法,同时将控制权交给相应的action。在该action中可以使用Action.isCancelled(HttpServletRequest)方法判断是否被取消了。如果返回true表示这个action被取消了,否则表示这个action没有被取消。

请注意,如果您修改了html:cancel标签的property属性值,那么struts提供的cancel探测机制就失效了,您自己必须提供类似的机制。

下面是可取消的action的配置文件,注意<set-property property="cancellable" value="true"/>这一行,如果不添加Struts会抛出org.apache.struts.action.InvalidCancelException异常。这是我在完成本指南的过程中发现的唯一向下不兼容的地方。

Xml代码 复制代码   收藏代码
  1. < action   path = "/cancel"     
  2.    type = "org.solo.struts.action.CancelAction"   name = "cancelForm"   scope = "request" >   
  3.    < set-property   property = "cancellable"   value = "true" />   
  4.    < forward   name = "success"   path = "/cancel.jsp"   />   
  5. </ action >   
<action path="/cancel" 
  type="org.solo.struts.action.CancelAction" name="cancelForm" scope="request">
  <set-property property="cancellable" value="true"/>
  <forward name="success" path="/cancel.jsp" />
</action>

 下面是html:cancel标签的代码:

Html代码 复制代码   收藏代码
  1. < html:cancel > 取消 </ html:cancel >   
<html:cancel>取消</html:cancel>

 下面是对应的action中的代码:

Java代码 复制代码   收藏代码
  1. if (isCancelled(request)){      
  2.    //action被取消时要做的事情写在这里   
  3.    return  mapping.findForward( "cancel" );   
  4. } else {   
  5.    //action没有被取消时要做的事情写在这里   
  6.    return  mapping.findForward( "success" );   
  7. }  
if(isCancelled(request)){   
  //action被取消时要做的事情写在这里
  return mapping.findForward("cancel");
}else{
  //action没有被取消时要做的事情写在这里
  return mapping.findForward("success");
}

struts判断标签

html:cancel
html:cancel标签生成一个取消按钮。当点击该按钮后action servlet会绕过相应的form bean的validate()方法,同时将控制权交给相应的action。在该action中可以使用Action.isCancelled(HttpServletRequest)方法判断是否被取消了。如果返回true表示这个action被取消了,否则表示这个action没有被取消。

请注意,如果您修改了html:cancel标签的property属性值,那么struts提供的cancel探测机制就失效了,您自己必须提供类似的机制。

下面是可取消的action的配置文件,注意<set-property property="cancellable" value="true"/>这一行,如果不添加Struts会抛出org.apache.struts.action.InvalidCancelException异常。这是我在完成本指南的过程中发现的唯一向下不兼容的地方。

Xml代码 复制代码   收藏代码
  1. < action   path = "/cancel"     
  2.    type = "org.solo.struts.action.CancelAction"   name = "cancelForm"   scope = "request" >   
  3.    < set-property   property = "cancellable"   value = "true" />   
  4.    < forward   name = "success"   path = "/cancel.jsp"   />   
  5. </ action >   
<action path="/cancel" 
  type="org.solo.struts.action.CancelAction" name="cancelForm" scope="request">
  <set-property property="cancellable" value="true"/>
  <forward name="success" path="/cancel.jsp" />
</action>

 下面是html:cancel标签的代码:

Html代码 复制代码   收藏代码
  1. < html:cancel > 取消 </ html:cancel >   
<html:cancel>取消</html:cancel>

 下面是对应的action中的代码:

Java代码 复制代码   收藏代码
  1. if (isCancelled(request)){      
  2.    //action被取消时要做的事情写在这里   
  3.    return  mapping.findForward( "cancel" );   
  4. } else {   
  5.    //action没有被取消时要做的事情写在这里   
  6.    return  mapping.findForward( "success" );   
  7. }  
if(isCancelled(request)){   
  //action被取消时要做的事情写在这里
  return mapping.findForward("cancel");
}else{
  //action没有被取消时要做的事情写在这里
  return mapping.findForward("success");
}

猜你喜欢

转载自xiaoxuejie.iteye.com/blog/1131707