IT教程 | 加入收藏 | 简体 | 繁体
Struts:Java基础StrutsSpringHibernateIbatis框架整合GUI编程Ejb分布式开发
当前位置: 首页 > Java教程 > Struts

struts.xml文件结构的实例详解

2012-03-28来源:[www.121ask.com]热度:0℃ 【字体:

struts.xml文件是整个Struts 2框架的核心,下面提供了一个最完整的struts.xml文件,这个文件没有任何实际意义,仅仅是一个struts.xml文件示范。

<?xml version="1.0" encoding="GBK"?>

<!-- 下面指定Struts 2配置文件的DTD信息 -->

<!DOCTYPE struts PUBLIC

        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

        "http://struts.apache.org/dtds/struts-2.0.dtd">

<!-- strutsStruts 2配置文件的根元素 -->

<struts>

                                 <!-- 下面元素可以出现0次,也可以无限多次 -->

                                 <constant name="" value="" />

                                 <!-- 下面元素可以出现0次,也可以无限多次 -->

                                 <bean type="" name="" class="" scope="" static="" optional="" />

                                 <!-- 下面元素可以出现0次,也可以无限多次 -->

                                 <include file="" />

                                 <!-- package元素是Struts配置文件的核心,该元素可以出现0次,或者无限多次 -->

                                 <package name="必填的包名" extends="" namespace="" abstract=""

                                    externalReferenceResolver>

                                    <!-- 该元素可以出现,也可以不出现,最多出现一次 -->

                                    <result-types>

                                        <!-- 该元素必须出现,可以出现无限多次-->

                                        <result-type name="" class="" default="true|false">

                                            <!-- 下面元素可以出现0次,也可以无限多次 -->

                                            <param name="参数名">参数值</param>*

                                        </result-type>

                                    </result-types>

                                    <!-- 该元素可以出现,也可以不出现,最多出现一次 -->

                                    <interceptors>

                                        <!-- 该元素的interceptor元素和interceptor-stack至少出现其中之一,

                                        也可以二者都出现 -->

                                        <!-- 下面元素可以出现0次,也可以无限多次 -->

                                        <interceptor name="" class="">

                                            <!-- 下面元素可以出现0次,也可以无限多次 -->

                                            <param name="参数名">参数值</param>*

                                        </interceptor>

                                        <!-- 下面元素可以出现0次,也可以无限多次 -->

                                        <interceptor-stack name="">

                                            <!-- 该元素必须出现,可以出现无限多次-->

                                            <interceptor-ref name="">

                                                <!-- 下面元素可以出现0次,也可以无限多次 -->

                                                <param name="参数名">参数值</param>*

                                            </interceptor-ref>

                                        </interceptor-stack>

                                    </interceptors>

                                    <!-- 下面元素可以出现0次,也可以无限多次 -->

                                    <default-interceptor-ref name="">

                                        <!-- 下面元素可以出现0次,也可以无限多次 -->

                                        <param name="参数名">参数值</param>

                                    </default-interceptor-ref>

                                    <!-- 下面元素可以出现0次,也可以无限多次 -->

                                    <default-action-ref name="">

                                        <!-- 下面元素可以出现0次,也可以无限多次 -->

                                        <param name="参数名">参数值</param>*

                                    </default-action-ref>?

                                    <!-- 下面元素可以出现0次,也可以无限多次 -->

                                    <global-results>

                                        <!-- 该元素必须出现,可以出现无限多次-->

                                        <result name="" type="">

                                            <!-- 该字符串内容可以出现0次或多次 -->

                                            映射资源

                                            <!-- 下面元素可以出现0次,也可以无限多次 -->

                                            <param name="参数名">参数值</param>*

                                        </result>

                                    </global-results>

                                    <!-- 下面元素可以出现0次,也可以无限多次 -->

                                    <global-exception-mappings>

                                        <!-- 该元素必须出现,可以出现无限多次-->

                                        <exception-mapping name="" exception="" result="">

                                            异常处理资源

                                            <!-- 下面元素可以出现0次,也可以无限多次 -->

                                            <param name="参数名">参数值</param>*

                                        </exception-mapping>

                                    </global-exception-mappings>

                                    <action name="" class="" method="" converter="">

                                        <!-- 下面元素可以出现0次,也可以无限多次 -->

                                        <param name="参数名">参数值</param>*

                                        <!-- 下面元素可以出现0次,也可以无限多次 -->

                                        <result name="" type="">

                                            映射资源

                                            <!-- 下面元素可以出现0次,也可以无限多次 -->

                                            <param name="参数名">参数值</param>*

                                        </result>

                                        <!-- 下面元素可以出现0次,也可以无限多次 -->

                                        <interceptor-ref name="">

                                            <!-- 下面元素可以出现0次,也可以无限多次 -->

                                            <param name="参数名">参数值</param>*

                                        </interceptor-ref>

                                        <!-- 下面元素可以出现0次,也可以无限多次 -->

                                        <exception-mapping name="" exception="" result="">

                                            异常处理资源

                                            <!-- 下面元素可以出现0次,也可以无限多次 -->

                                            <param name="参数名">参数值</param>*

                                        </exception-mapping>

                                    </action>

                                 </package>*

<struts>

上面的struts.xml配置文件是一个非常全面的配置文件,包含了Struts 2的全部配置元素。上面配置文件主要用于帮助对XML DTD不太熟悉的读者。

[NextPage]

实际上,如果读者需要熟悉XML文件的DTD(元素类型定义)语法,通过查看Struts 2配置文件的DTD信息,同样可以了解Struts 2配置文件的结构。下面是Struts 2配置文件的DTD文件代码。

<!--

   Struts configuration DTD.

   Use the following DOCTYPE

  

   <!DOCTYPE struts PUBLIC

                                 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

                                 "http://struts.apache.org/dtds/struts-2.0.dtd">

-->

<!ELEMENT struts (package|include|bean|constant)*>

<!ELEMENT package (result-types?, interceptors?, default-interceptor-ref?, default-action-ref?, global-results?, global-exception-mappings?, action*)>

<!ATTLIST package

    name CDATA #REQUIRED

    extends CDATA #IMPLIED

    namespace CDATA #IMPLIED

    abstract CDATA #IMPLIED

    externalReferenceResolver NMTOKEN #IMPLIED

<!ELEMENT result-types (result-type+)>

<!ELEMENT result-type (param*)>

<!ATTLIST result-type

    name CDATA #REQUIRED

    class CDATA #REQUIRED

    default (true|false) "false"

<!ELEMENT interceptors (interceptor|interceptor-stack)+>

<!ELEMENT interceptor (param*)>

<!ATTLIST interceptor

    name CDATA #REQUIRED

    class CDATA #REQUIRED

<!ELEMENT interceptor-stack (interceptor-ref+)>

<!ATTLIST interceptor-stack

    name CDATA #REQUIRED

<!ELEMENT interceptor-ref (param*)>

<!ATTLIST interceptor-ref

    name CDATA #REQUIRED

<!ELEMENT default-interceptor-ref (param*)>

<!ATTLIST default-interceptor-ref

    name CDATA #REQUIRED

<!ELEMENT default-action-ref (param*)>

<!ATTLIST default-action-ref

    name CDATA #REQUIRED

<!ELEMENT global-results (result+)>

<!ELEMENT global-exception-mappings (exception-mapping+)>

<!ELEMENT action (param|result|interceptor-ref|exception-mapping)*>

<!ATTLIST action

    name CDATA #REQUIRED

    class CDATA #IMPLIED

    method CDATA #IMPLIED

    converter CDATA #IMPLIED

<!ELEMENT param (#PCDATA)>

<!ATTLIST param

    name CDATA #REQUIRED

<!ELEMENT result (#PCDATA|param)*>

<!ATTLIST result

    name CDATA #IMPLIED

    type CDATA #IMPLIED

<!ELEMENT exception-mapping (#PCDATA|param)*>

<!ATTLIST exception-mapping

    name CDATA #IMPLIED

    exception CDATA #REQUIRED

    result CDATA #REQUIRED

<!ELEMENT include (#PCDATA)>

<!ATTLIST include

    file CDATA #REQUIRED

<!ELEMENT bean (#PCDATA)>

<!ATTLIST bean

    type CDATA #IMPLIED

    name CDATA #IMPLIED

    class CDATA #REQUIRED

    scope CDATA #IMPLIED

    static CDATA #IMPLIED

    optional CDATA #IMPLIED

<!ELEMENT constant (#PCDATA)>

<!ATTLIST constant

    name CDATA #REQUIRED

    value CDATA #REQUIRED

通过上面给出的struts.xml配置文件范例,以及Struts 2配置文件的DTD信息,我们已经可以全面掌握Struts 2配置文件的文件结构了。

以上IT文章《struts.xml文件结构的实例详解》由名客技术网[www.121ask.com]提供阅读!
推广信息
推广信息
名客技术网是一个免费为广大IT技术人员提供IT教程,绿色软件,asp/php/jsp/java/net等实例视频教程,CMS教程,破解软件下载以及学习相关源码、知识的IT网站。
名客技术网如果无意之中侵犯了您的版权,请来电告知,本站将在3个工作日内删除 QQ:175352796
Copyright 2011-2017 Powered by 121ASK.COM, All Rights Reserved.
备案号:鄂ICP备11013833号-3