strust1的的异常--does not contain specified method (check logs)

在使用DispatchAction时出现了这个问题,从这句话分析,就是没有在指定的类中,找到对应的方法。

先说结论: 在Action中定义的方法(要在参数中使用的方法),参数一定要固定为 

(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response )

--------------------------------

这种错误,一般在保证所有路径的拼写都正确的情况下应该就能避免,

扫描二维码关注公众号,回复: 756420 查看本文章

那接着分析一下,struts是如何从jsp一步步找到这个方法呢?

1 页面上 action的路径,以及对应的struts配置文件中定义的parameter的参数名(我这叫method)属性值,这个属性值应对应着 Action类的方法名。

2 确认了以上路径都正确的情况下,考虑到DispatchAction对应“方法”的方式,发现原来是方法多了一个参数。

顺便看了下DispatchAction源代码,看到里面找方法的时候,用的是

 method = clazz.getMethod(name, types);

其中

clazz = getClass();

types = (new Class[] {

            org.apache.struts.action.ActionMapping.class,  org.apache.struts.action.ActionForm.class,  javax.servlet.http.HttpServletRequest.class,  javax.servlet.http.HttpServletResponse.class

        });

就是说,DispatchAction只会将参数固定为以上4中的函数作为控制器方法使用。

猜你喜欢

转载自javaeedevelop.iteye.com/blog/1830709