2

我在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

一旦我在包中添加了 extends='struts-default' 作为

<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 可以正常启动。

所以我的问题是当我在 struts.xml 中添加一个“包”时。包是否必须从“struts-default”包扩展?我用谷歌搜索了这个,但“扩展”属性只是包元素的一个选项属性。那我为什么会有这个问题?

4

1 回答 1

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" />
于 2013-03-14T14:54:15.640 回答