Constant Configuration(常量配置)

来源:互联网 发布:算法导论第二版百度云 编辑:程序博客网 时间:2024/05/16 11:44

常量提供了一个简单的方法定义struts应用通过定义键值,这些键值修改框架和插件的行为。这里有两种键的角色。第一种为:他们被用来重写已设定的值,比如文件上传的最大值或者是struts框架是否应该在"devMode"模式下。第二种:他们确定了Bean的实现,在一个给定的类型下的多个实现中,哪一个应该被选择。

常量能够在多个文件中被声明。默认的,常量搜索按以下的顺序,允许后面的文件重写前面的:struts-default.xml,struts-plugin.xml,struts.xml,struts.properties,web.xml。


在WebWork中struts.properties文件提供了向后兼容性。


在多种多样的XML变量中,常量元素有两个必须的属性:name和value。


在struts.properties文件中,每一个实体被当做一个常量。

在web.xml文件中,任何FilterDispatcher的初始化的参数被作为常量。

常量例子(struts.xml)

<struts>

<constant name="struts.devMode" value="true"/>

</struts>

在web.xml文件中

<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">    <filter>        <filter-name>struts</filter-name>        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>        <init-param>        <param-name>struts.devMode</param-name>        <param-value>true</param-value>        </init-param>    </filter>    ...</web-app>

0 0
原创粉丝点击