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異常。這是我在完成本指南的過程中發現的唯一向下不兼容的地方。
- < 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 > ??
<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:cancel > 取消 </ html:cancel > ??
<html:cancel>取消</html:cancel>
?下面是對應的action中的代碼:
- if (isCancelled(request)){??? ??
- ?? //action被取消時要做的事情寫在這里 ??
- ?? return ?mapping.findForward( "cancel" ); ??
- } else { ??
- ?? //action沒有被取消時要做的事情寫在這里 ??
- ?? return ?mapping.findForward( "success" ); ??
- }??
if(isCancelled(request)){ //action被取消時要做的事情寫在這里 return mapping.findForward("cancel"); }else{ //action沒有被取消時要做的事情寫在這里 return mapping.findForward("success"); }
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
