I declared a package in struts.xml
. But tomcat6 can't startup since I added it. The configuration in struts.xml
is:
<package name="pkg2" namespace="/0314">
<interceptors>
<interceptor name="myInterceptor" class="com.chailie.test4.MyInterceptor"/>
<interceptor-stack name="myInterceptorStack">
<interceptor-ref name="myInterceptor"/>
</interceptor-stack>
</interceptors>
<global-results>
<result name="success">/success.jsp</result>
</global-results>
<action name="test1" class="com.chailie.test4.HelloWorld1">
<result name="success">/success.jsp</result>
<interceptor-ref name="myInterceptorStack"/>
</action>
</package>
When I booted tomcat6 the exception's stacktrace was:
INFO: Choosing bean (struts) for interface org.apache.struts2.dispatcher.StaticContentLoader
三月 14, 2013 10:07:52 下午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
INFO: Choosing bean (struts) for interface com.opensymphony.xwork2.UnknownHandlerManager
三月 14, 2013 10:07:53 下午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
SEVERE: Dispatcher initialization failed
Unable to load configuration. - result - file:/C:/tomcat6/webapps/sstart/WEB-INF/classes/struts.xml:57:27
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:390)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:436)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: No result type specified for result named 'success', perhaps the parent package does not specify the result type? - result - file:/C:/tomcat6/webapps/sstart/WEB-INF/classes/struts.xml:57:27
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java:636)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadGlobalResults(XmlConfigurationProvider.java:807)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:477)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:278)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
... 31 more
三月 14, 2013 10:07:53 下午 org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
三月 14, 2013 10:07:53 下午 org.apache.catalina.core.StandardContext start
SEVERE: Context [/sstart] startup failed due to previous errors
三月 14, 2013 10:07:53 下午 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
Once I added extends='struts-default' in package as
<package name="pkg2" namespace="/0314" extends='struts-default'>
<interceptors>
<interceptor name="myInterceptor" class="com.chailie.test4.MyInterceptor"/>
<interceptor-stack name="myInterceptorStack">
<interceptor-ref name="myInterceptor"/>
</interceptor-stack>
</interceptors>
<global-results>
<result name="success">/success.jsp</result>
</global-results>
<action name="test1" class="com.chailie.test4.HelloWorld1">
<result name="success">/success.jsp</result>
<interceptor-ref name="myInterceptorStack"/>
</action>
</package>
the tomcat6 could startup properly.
So my question is when I add one "package" in struts.xml. Does the package have to extend from "struts-default" package? I googled this but the "extends" attribute is just an option attribute for package element. Then why would I have this issue?
Check the original strus-default.xml , you'll see that it defines all default interceptors and results, you are not defining results in yours, that's why is most likely failing. I can't test it right now, but I would assume that if you add the definition for the dispatcher result and the default class reference, then it should start without extending it.
<result-types>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
</result-types>
<default-class-ref class="com.opensymphony.xwork2.ActionSupport" />