0

我已按照 apache 教程进行操作,但以下代码遇到错误。

错误>>>>

Caused by: org.xml.sax.SAXParseException; systemId:     
file:/C:/Users/target/Project-1.0/WEB-
INF/classes/struts.xml; lineNumber: 53; columnNumber: 15; The content of element type "package"   
must match "(result-types?,interceptors?,default-interceptor-ref?,default-action-ref?,default-  
class-ref?,global-results?,global-exception-mappings?,action*)".

请注意,一旦我复制重定向代码就会出错,动作和包的定义是正确的。代码

     <package name="default" namespace="/" extends="struts-default">

        <default-action-ref name="UnderConstruction"></default-action-ref>

            <action name="UnderConstruction">
                <result>notFound.jsp</result>
            </action>

            <result-types>
                <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
            </result-types>

            <action ....>
            </action>
              ,,,
    </package>

当我更改以下行时

 <result>notFound.jsp</result> 

 <result type="tiles">notFound.jsp</result>  

该应用程序将运行,但是当我输入错误的地址时,它不会显示 notFound.jsp 页面,只是抛出一个未找到的操作异常。

当我尝试以下代码时,应用程序会运行,但它不会将错误的请求重定向到正在建设的页面

    <package name="default" namespace="/" extends="struts-default">

            <result-types>
                <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
            </result-types>

            <action ....>
            </action>
              ,,,
    </package>

      <package name="Hello" extends="struts-default">
           <default-action-ref name="UnderConstruction"></default-action-ref>

            <action name="UnderConstruction">
                <result>notFound.jsp</result>
            </action>
       </package>
4

1 回答 1

3

您显示的上述配置用于瓷砖集成。您不能简单地复制粘贴并使其像火箭一样工作。但是有多种方法可以实现您的目标,其中一些方法如下:

第一种方法

为错误或异常创建全局结果声明

<global-results>
    <result name="error">/Error.jsp</result>
    <result name="specific_exception">/Unique.jsp</result>
    <result name="login" type="redirectAction">Login.jsp</result>
</global-results>

并从您的基于操作的入侵中验证并返回相应的字符串 ex 错误或成功。

第二种方法

你可以在你的动作映射中重定向自己

<action name="your_action_name">
     <result type="success">Success.jsp</result>
     <result type="error">notFound.jsp</result>
 </action>
于 2013-03-13T06:26:28.530 回答