我在struts.xml
中声明了一个包。但是自从我添加它以来,tomcat6无法启动。 struts.xml
中的配置为:
<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>
当我启动tomcat6时,异常的堆栈跟踪是:
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
我添加了extend =&#39; struts-default&#39;在包中作为
<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>
tomcat6可以正常启动。
所以我的问题是当我添加一个&#34;包&#34;在struts.xml中。包是否必须从&#34; struts-default&#34;包?我用谷歌搜索了这个,但是&#34;延伸了#34; attribute只是package元素的option属性。那为什么我会遇到这个问题?
答案 0 :(得分:4)
检查原始strus-default.xml,你会发现它定义了所有默认拦截器和结果,你没有在你的结果中定义结果,这就是为什么最有可能失败的原因。 我现在无法测试它,但我认为如果你为调度程序结果和默认类引用添加定义,那么它应该在不扩展它的情况下启动。
<result-types>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
</result-types>
<default-class-ref class="com.opensymphony.xwork2.ActionSupport" />