首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

strust1的的错误-does not contain specified method (check logs)

2013-03-19 
strust1的的异常--does not contain specified method (check logs)在使用DispatchAction时出现了这个问题

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

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

?

?

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

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

?

?

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

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

?

?

那接着分析一下,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中的函数作为控制器方法使用。

热点排行