當我在 Eclipse IDE 環境中學習 struts 2 的過程中,進行編輯 struts.xml 時碰到提示下列的問題
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*)”.
有問題的 struts.xml 內容大略如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" namespace="/" extends="jasperreports-default">
<action name="myJasperTest" class="tw.idv.bestlong.test.action.JasperAction">
<result name="success" type="jasper">
<param name="location">/jasper/our_compiled_template.jasper</param>
<param name="datasource">myList</param>
<param name="format">PDF</param>
</result>
</action>
<result-types>
<result-type name="jasper" class="org.apache.struts2.views.jasperreports.JasperReportsResult"/>
</result-types>
</package>
</struts> |
這是因為沒有依據 DTD 中定義的 Element 順序,所以只要調整內容的順序如下就可以通過檢查了。
1 2 3 4 5 6 7 8 9 10 11 12 13
| <package name="default" namespace="/" extends="jasperreports-default">
<result-types>
<result-type name="jasper" class="org.apache.struts2.views.jasperreports.JasperReportsResult"/>
</result-types>
<action name="myJasperTest" class="tw.idv.bestlong.test.action.JasperAction">
<result name="success" type="jasper">
<param name="location">/jasper/our_compiled_template.jasper</param>
<param name="datasource">myList</param>
<param name="format">PDF</param>
</result>
</action>
</package> |