当然是打印出"execute"啦,而且接照你这种写法,你这个TestCaseAction就完全是一个Action,而不是一个DispatchAction。原因如下:因为DispatchAction本身就是扩展于Action,然后重写过Action中的execute方法,这是核心来的,在execute方法里头实现参数(parameter)功能。但是你上面的代码中,你又重新写过DispatchAction的核心方法execute,所以DispatchAction参数(parameter)功能就没能实现。
因为控制器直接调用Action子类的execute方法,所以就打印出"execute"。解决方法:
不要在DispatchAction的子类重写execute方法,即删除掉TestCaseAction中的execute方法建议去看看struts的源代码以下是DispatchAction.java的部分源代码:
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception { // 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);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
message);
return (null);
} // Identify the method name to be dispatched to.
// dispatchMethod() will call unspecified() if name is null
String name = request.getParameter(parameter); // Invoke the named method, and return the result
return dispatchMethod(mapping, form, request, response, name);
}
因为控制器直接调用Action子类的execute方法,所以就打印出"execute"。解决方法:
不要在DispatchAction的子类重写execute方法,即删除掉TestCaseAction中的execute方法建议去看看struts的源代码以下是DispatchAction.java的部分源代码:
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception { // 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);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
message);
return (null);
} // Identify the method name to be dispatched to.
// dispatchMethod() will call unspecified() if name is null
String name = request.getParameter(parameter); // Invoke the named method, and return the result
return dispatchMethod(mapping, form, request, response, name);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货