<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");
}
本文介绍如何在Struts框架中正确配置和使用取消按钮。通过修改struts-config.xml文件并添加特定属性,可以实现点击取消按钮后的指定行为。此外,还需在对应的Action类中增加处理逻辑。
716

被折叠的 条评论
为什么被折叠?



