今天学习struts2时碰到一个蛋疼的错误,提示无法加载struts.xml,
但是我的struts.xml只有很简单的一部分
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="com.test.action" namespace="/">
<action name="logon" class="com.test.action.LogonAction">
<result name="success">/ListToXml.jsp</result>
</action>
</package>
</struts>
百度后,基本都是说要导入一些jar包什么的,可是我遇到的这个问题不是他们描述的那样。
然后我看到错误提示部分有这样一句话,说是parent package无法指定action-result 中的success,
再次百度后发现是由于我的struts.xml是自己写的,所以在package漏写了一句extends="struts-default"
这个文件在struts-core-XX.jar中,好像是用来处理action-result部分的配置。
Caused by: No result type specified for result named 'success', perhaps the parent package does not specify the result type? - result - file:/D:/apache-tomcat-6.0.20/webapps/logonProject/WEB-INF/classes/struts.xml:6:27
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java:612)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:365)
... 36 more
最后总结解决方案:在struts.xml的package配置中,加上一句 extends="struts-default"