原来用的struts2.0版本,运行项目没有问题。后来换了struts2.2.1版本后,只要访问Action,都会出现
java.lang.NoSuchMethodException: com.struts.action.UserAction.create()类似的错误,就是说Action中找不到create这个方法。
struts.xml
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
login,register
update
/main.jsp
/index.jsp
[/code]
我设定的是方法拦截,所以当进入user_update.action的时候,没有问题,因为它可以进入拦截器。但是我没有拦截login和register方法,进入这两个方法时就会出错。说找不到create方法。我Action里面没有这个方法,肯定找不到。而且继承的ActionSupport的里面也没有这个方法,只有excute方法。不知道为什么struts会非要找这个create方法!后来上网查了半天,人家说去掉这部分就可以。
defaults.xml
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
/error.jsp
<global-exception-mappings>
<exception-mapping exception="java.lang.NullPointerException" result="error" />
<exception-mapping exception="java.lang.Exception" result="error" />
</global-exception-mappings>
</package>
[/code]
试了下,果然奏效。但是用原来struts2.0的版本没有这样的问题啊!不知道为什么,哪位高人来解释下,感激不尽!最好能带 struts的源代码分析下!还有struts2.0和2.1之后的地方,有哪些区别?
Oh My God!现在又不行了。不知道是不是我刚才手动加的create方法没去掉,现在又报这个错误,蛋疼啊!高手速来解答!感激不尽啊!