-1

这是我的代码

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>

我不知道发生了什么错误错误显示元素类型“包”的内容必须匹配“(结果类型?,拦截器?,默认拦截器引用?,默认操作引用?,默认类引用? ,global-results?,global-exception-mappings?,action*)”。请纠正我

4

1 回答 1

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>
于 2015-10-08T17:54:10.773 回答