经常有人在配置Struts1.2的struts-config.xml配置文件时,配置错误,

 

错误的配置方式:

<!-- HelloWolrdAction配置 -->
 <action path="/helloWorldAction" name="HelloWorldTestAction" className="pack.java.action.HelloWorldAction" input="/error.jsp" scope="request" parameter="p" >
 <forward name="success" path="/main.jsp"></forward>
 <forward name="failure" path="/index.jsp" redirect="true"></forward>
 </action>

 

正确的配置方式:

 

 

<!-- HelloWolrdAction配置 -->
 <action path="/helloWorldAction" name="HelloWorldTestAction" type="pack.java.action.HelloWorldAction" input="/error.jsp" scope="request" parameter="p" >
 <forward name="success" path="/main.jsp"></forward>
 <forward name="failure" path="/index.jsp" redirect="true"></forward>
 </action>

 

注意className和type的区别。

 

错误信息:

严重: End event threw exception
java.lang.NoSuchMethodException: No such accessible method: addForwardConfig() on object: pack.java.action.HelloWorldAction
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:214)
at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:208)
at org.apache.commons.digester.Rule.end(Rule.java:228)
at org.apache.commons.digester.Digester.endElement(Digester.java:1067)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator.endNamespaceScope(XMLNSDTDValidator.java:263)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:2028)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:901)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2939)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.apache.commons.digester.Digester.parse(Digester.java:1572)
at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:738)
at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:687)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:333)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2012-6-6 23:57:46 org.apache.struts.action.ActionServlet handleConfigException
严重: Parsing error processing resource path /WEB-INF/struts-config.xml