Struts 1.2.2 新功能体验(二)

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

从1.2.2开始对DispatchAction中实现isCancelled的功能进行了简化.

在DispatchAction的子类中只需override DispatchAction的cancelled

方法即可,而不用在1.1中要通过override execute方法来实现.

至于实现的原理可参见下面的Struts1.1.2中DispatchAction源代码.

/**

* Process the specified HTTP request, and create the corresponding HTTP

* response (or forward to another web component that will create it).

* Return an <code>ActionForward</code> instance describing where and how

* control should be forwarded, or <code>null</code> if the response has

* already been completed.

*

* @param mapping The ActionMapping used to select this instance

* @param form The optional ActionForm bean for this request (if any)

* @param request The HTTP request we are processing

* @param response The HTTP response we are creating

*

* @exception Exception if an exception occurs

*/

public ActionForward execute(ActionMapping mapping,

ActionForm form,

HttpServletRequest request,

HttpServletResponse response)

throws Exception {

//请注意下面1.2.2新增的代码

if (isCancelled(request)) {

ActionForward af = cancelled(mapping, form, request, response);

if (af != null) {

return af;

}

}

// Identify the request parameter containing the method name

String parameter = mapping.getParameter();

if (parameter == null) {

String message =

messages.getMessage("dispatch.handler", mapping.getPath());

log.error(message);

throw new ServletException(message);

}

// Get the method's name. This could be overridden in subclasses.

String name = getMethodName(mapping, form, request, response, parameter);

// Prevent recursive calls

if ("execute".equals(name) || "perform".equals(name)){

String message =

messages.getMessage("dispatch.recursive", mapping.getPath());

log.error(message);

throw new ServletException(message);

}

/**

* 在DispatchAction子类中需要Override此方法!

* Method which is dispatched to when the request is a cancel button submit.

* Subclasses of <code>DispatchAction</code> should override this method if

* they wish to provide default behavior different than returning null.

* @since Struts 1.2.0

*/

protected ActionForward cancelled(ActionMapping mapping,

ActionForm form,

HttpServletRequest request,

HttpServletResponse response)

throws Exception {

return null;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航