struts.xml中包含的是开发Action所需要修改的配置。基本结构如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<include file="example.xml"/>
<!-- Add packages here -->
</struts>
include标签",它的意思是导入一个配置文件,file属性指向文件的路径。
要注意一点的是,导入的文件必需与struts.xml有两样的约束与格式,如下面是example.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="example" namespace="/example" extends="struts-default">
<action name="HelloWorld" class="example.HelloWorld">
<result>/example/HelloWorld.jsp</result>
</action>
<action name="Login_*" method="{1}" class="example.Login">
<result name="input">/example/Login.jsp</result>
<result type="redirect-action">Menu</result>
</action>
<action name="*" class="example.ExampleSupport">
<result>/example/{1}.jsp</result>
</action>
<!-- Add actions here -->
</package>
</struts>
include的好处就是可以很方面地做到模块化,以便管理,除了手动include之外,struts2中还有一些会自动include进来的文件,那就是struts-default.xml和struts-plugin.xml,struts-default.xml可以在struts2-core.jar中找到,struts-plugin.xml可以在每个插件的jar包中找到并且会在系统启动时被加载。struts-default.xml中主要配置的是:结果类、型拦截器、拦截器堆栈、包(package)以及 Web 应用执行环境(也可以在“struts.properties”中配置)的配置信息。
package标签是用来把那些需要共享的通用信息——例
如拦截器堆栈或 URL命名空间——的配置组织在一起的。它通常由
Action的配置组成,但也可以包括任何类型的配置信息。
在struts-default.xml可以找到这么一段:
<package name="struts-default" abstract="true">
<result-types>
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
<!-- Deprecated name form scheduled for removal in Struts 2.1.0. The camelCase versions are preferred. See ww-1707 -->
<result-type name="redirect-action" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="plaintext" class="org.apache.struts2.dispatcher.PlainTextResult" />
</result-types>
这个标签的属性包括有:
- name ——开发人员为这个 Package指定的唯一的名字。
- extends —— 当前这个 Package所继承的 Package的名字,
被继承的 Package中所有的配置信息(包括 Action的配
置)都可以在新的命名空间下,新的 Package里面被使
用。
- namespace ——命名空间提供了从 URL到 Package的映
射。也就是说,如果两个不同的 Package,其命名空间分别
为“package1”和“package2”,那么URL差不多就是
14 | 深入浅出STRUTS 2
InfoQ中文站:时刻关注企业软件开发领域的变化与创新
“/myWebApp/package1/my.action” 和
“/myWebApp/package2/my.action”这样的形式。
- abstract ——如果这个属性的值为“true”,那么这个
Package就只是一个配置信息的组合,也就无法通过
Package的名字来访问其中配置的 Action。可以看到struts-default.xml中package的abstract为true,因此它只是一个配置信息的组合。
只有继承了正确的父 Package,那么你才能用到所需的预先配置
好的特性。在大多数情况下,我们都应该继承“struts-default.xml”
配置文件中的“strust-default”Package
bean标签
constant标签
用来覆盖default.properties里的默认的配置
分享到:
相关推荐
struts.xml和applicationContext.xml、web.xml的配置
spring在web.xml中和在struts中的不同配置..pdf
绝对的好东西 struts2.0中struts.xml配置文件详解
Struts框架中struts-config.xml文件配置小结
struts-config.xml struts标准配置文件 struts-config
SSH(Struts,Spring,Hibernate)struts.xml文件配置
struts1 web.xml struts1配置
struts-config.xml配置文件对学struts的人必备的查找资料。
Dom4j解析struts2框架的struts.xml,自定义struts框架需要解析配置文件
struts-config.xml配置文件 struts-config.xml配置文件 struts-config.xml配置文件
flex4,struts2.3兼容配置web.xml
struts.xml文件详解.docstruts.xml文件详解.docstruts.xml文件详解.docstruts.xml文件详解.doc
flex4,struts2.3兼容配置web.xml中的filter
struts.xml文件配置解释,对action配置进行说明
struts2中两种validation.xml的配置方式
Struts2手动搭建“所有的jar包(全)”及相应的struts.xml和web.xml全套
Struts-config.xml配置详解,介绍Struts-config中8个元素配置方法。
以前和struts2一起使用的配置文件,struts2的核心控制器
NULL 博文链接:https://wellfrog.iteye.com/blog/612014
struts2.0中struts.xml配置文件详解