这是我的代码
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>
<!-- ********************************************************** -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<!-- ********************************************************** -->
<package name="default" extends="struts-default">
<!-- *****************DEFAULT ACTION STARTS********************* -->
<default-action-ref name="somedefault" />
<!-- ******************************* -->
<action name="somedefault">
<result>/jsp/DefaultPage.jsp</result>
</action>
<!-- *****************DEFAULT ACTION ENDS********************* -->
<!-- *****************GLOBAL RESULTS STARTS********************* -->
<global-results>
<result name="null">/jsp/Fail1.jsp</result>
<result name="excep">/jsp/Fail2.jsp</result>
</global-results>
<!-- ******************GLOBAL RESULTS ENDS********************** -->
<!-- *************GLOBAL EXCEPTION MAPPING STARTS*************** -->
<global-exception-mappings>
<exception-mapping result="null" exception="java.lang.NullPointerException" />
<exception-mapping result="excep" exception="java.lang.Exception" />
</global-exception-mappings>
<!-- **************GLOBAL EXCEPTION MAPPING ENDS***************** -->
<!-- ******************OTHER ACTION STARTS*********************** -->
<action name="Calculator" class="com.action.Calculator">
<exception-mapping result="error" exception="java.lang.NumberFormatException" />
<exception-mapping result="none" exception="java.lang.NullPointerException" />
<result name="success">/jsp/Success.jsp</result>
<result name="error">/jsp/Error.jsp</result>
<result name="none">/jsp/Error1.jsp</result>
</action>
<!-- ************************************ -->
<action name="Action1" class="com.action.Action1">
<result name="success">/jsp/Success1.jsp</result>
</action>
<!-- ************************************ -->
<action name="Action2" class="com.action.Action2">
<result name="success">/jsp/Success1.jsp</result>
</action>
<!-- *********************OTHER ACTION ENDS********************** -->
</package>
<!-- ************************************************************ -->
</struts>
我不知道发生错误的是什么 错误显示 元素类型“package”的内容必须匹配“(结果类型?,拦截器?,默认 - 拦截器 - 参考?,默认 - 动作 - 参考?,默认 - 类 - 参考?,全局 - 结果?,全局 - 异常映射?,行动*)”。 请纠正我
答案 0 :(得分:1)
将默认操作的定义移动到定义其他操作的规范部分。我删除了注释并重新缩进,以便您可以更清楚地看到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>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default">
<default-action-ref name="somedefault" />
<global-results>
<result name="null">/jsp/Fail1.jsp</result>
<result name="excep">/jsp/Fail2.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="null" exception="java.lang.NullPointerException" />
<exception-mapping result="excep" exception="java.lang.Exception" />
</global-exception-mappings>
<action name="somedefault">
<result>/jsp/DefaultPage.jsp</result>
</action>
<action name="Calculator" class="com.action.Calculator">
<exception-mapping result="error" exception="java.lang.NumberFormatException" />
<exception-mapping result="none" exception="java.lang.NullPointerException" />
<result name="success">/jsp/Success.jsp</result>
<result name="error">/jsp/Error.jsp</result>
<result name="none">/jsp/Error1.jsp</result>
</action>
<action name="Action1" class="com.action.Action1">
<result name="success">/jsp/Success1.jsp</result>
</action>
<action name="Action2" class="com.action.Action2">
<result name="success">/jsp/Success1.jsp</result>
</action>
</package>
</struts>