`

struts2配置文件

阅读更多
一、Struts2配置文件
Struts2相关的配置文件有web.xml,struts.xml,struts.properties,struts-default.xml,velocity.properties,struts-default.vm。其中web.xml,struts.xml是必须的,其它的配置文件可选择。
它们在web应用中的功能如下:
web.xml:包含所有必须的框架组件的web部署描述符。
Struts.xml:配置包含result/view类型、action映射、拦截器等的Struts2的主要配置文件。
Struts.properties:配置struts2的框架属性。
Struts-default.xml:在文件在struts-action-x.x.jar中,该文件是应该被包含在struts.xml中的缺省配置。
Welocity.properties:重写了velocity的配置文件。
Struts-default.vm:相对于velocity的缺省配置。

二、Struts2配置元素
Struts2核心的配置文件是缺省的struts.xml。
必要的时候,缺省的配置文件可以包含其它的配置文件;struts文件可以放入jar中,并自动插入应用程序,这样每个模块可以包含自己的配置文件并自动配置。在Freemarker和Velocity模块中,模板也能从classpath中加载,所以整个模块可以作为一个简单的jar文件被包含。
Struts.xml配置文件可以包含Interceptor、Action类和Results。
Struts.xml配置元素说明:

1、Packages
Packages:packages把actions、results、results types、interceptors
和interceptor-stacks组装到一个逻辑单元中,从概念上讲,packages就像一个对象,可以被其它子包从写,而且可以拥有自己独立的部分。
Name属性是packages的必填元素,它作为一个关键字被后边的包引用;extends元素是可选的,它允许包扩展一个和多个前边定义的包。注意,
struts.xml文件是至上而下处理的,所有被扩展的包,需要在扩展包前定义。
Abstract元素是可选的,它可以申明一个不包含actions的配置文件。

2、Namespace
Namespace元素把actions细分到逻辑模块,每一个namespace都有自己的
前缀(prefix),namespace避免了action之间的名字冲突,当前缀出现在URI中时,这些标签都是名字空间感知的(“namespace aware”),所以这些namespace prefix不必嵌入到表单或连接中。
Default的namespace是一个空字符串“”,如果在指定的配置文件中,没有找到action,缺省的namespace也会被查找。 Local/global策略允许应用程序在action “extends”元素层次结构之外,有全局的action配置。缺省的namespace也可以不在package中申明。
Namespace prefix可以注册为java的申明式安全,以确保授权的用户才能访问namespace的资源。
Root namespace(“/”)也被支持,root就是当直接请求context path的时候的namespace。

3、Include
Include元素使得框架能应用“divide and conquer”来配置文件。被include
的每个配置文件必须和struts.xml有一样的格式,一个大的项目可以采用这样方式来组织程序模块。
Include元素也可以和package交替出现,框架将按照顺序加载配置文件。

4、Interceptor configuration
Interceptor允许应用程序在Action方法执行前后定义执行代码,
Interceptor在应用程序开发中十分重要,对于Interceptor有许多用例,如validation, property population, security, logging, 和profiling。
Interceptor被定义为一个Java类,Interceptor也可以组装成Interceptor-stack,他们将按照定义的顺序执行。
在struts-default.xml中定义了一些缺省的Interceptor-stack,以便框架能很好地运行。

5、Action
Action是框架的“工作单元”。Action可以指定一个Interceptor-stack、
一序列的return type和一序列的异常处理,但只有name属性是必须的。
 
配置参数说明如下:
 
struts.action.extension
The URL extension to use to determine if the request is meant for a Struts action
该属性指定需要Struts 2处理的请求后缀,该属性的默认值是action,即所有匹配*.action的请求都由Struts 2处理。如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开。

struts.configuration
The org.apache.struts2.config.Configuration implementation class
org.apache.struts2.config.Configuration接口名
该属性指定加载Struts 2配置文件的配置文件管理器。该属性的默认值是org.apache.Struts2.config.DefaultConfiguration,这是 Struts 2默认的配置文件管理器。如果需要实现自己的配置管理器,开发者则可以实现一个实现Configuration接口的类,该类可以自己加载Struts 2配置文件。

struts.configuration.files
A list of configuration files automatically loaded by Struts
struts自动加载的一个配置文件列表。该属性指定Struts 2框架默认加载的配置文件,如果需要指定默认加载多个配置文件,则多个配置文件的文件名之间以英文逗号(,)隔开。该属性的默认值为struts- default.xml,struts-plugin.xml,struts.xml,看到该属性值,读者应该明白为什么Struts 2框架默认加载struts.xml文件了。

struts.configuration.xml.reload
Whether to reload the XML configuration or not
该属性设置当struts.xml文件改变后,系统是否自动重新加载该文件。该属性的默认值是false。

struts.continuations.package
The package containing actions that use Rife continuations
含有actions的完整连续的package名称

struts.custom.i18n.resources
Location of additional localization properties files to load
加载附加的国际化属性文件(不包含.properties后缀)。该属性指定Struts 2应用所需要的国际化资源文件,如果有多份国际化资源文件,则多个资源文件的文件名以英文逗号(,)隔开。

struts.custom.properties
Location of additional configuration properties files to load
加载附加的配置文件的位置

struts.devMode
Whether Struts is in development mode or not
是否为struts开发模式

struts.dispatcher.parametersWorkaround
Whether to use a Servlet request parameter workaround necessary for some versions of WebLogic
(某些版本的weblogic专用)是否使用一个servlet请求参数工作区(PARAMETERSWORKAROUND)

struts.enable.DynamicMethodInvocation
Allows one to disable dynamic method invocation from the URL
允许动态方法调用

struts.freemarker.manager.classname
The org.apache.struts2.views.freemarker.FreemarkerManager implementation class
org.apache.struts2.views.freemarker.FreemarkerManager接口名

struts.i18n.encoding
The encoding to use for localization messages
国际化信息内码

struts.i18n.reload
Whether the localization messages should automatically be reloaded
是否国际化信息自动加载

struts.locale
The default locale for the Struts application
默认的国际化地区信息

struts.mapper.class
The org.apache.struts2.dispatcher.mapper.ActionMapper implementation class
org.apache.struts2.dispatcher.mapper.ActionMapper接口
指定将HTTP请求映射到指定 Action的映射器,Struts 2提供了默认的映射器:org.apache.struts2.dispatcher.mapper.DefaultActionMapper。默认映射器根据请求的前缀与Action的name属性完成映射。

struts.multipart.maxSize
The maximize size of a multipart request (file upload)
multipart请求信息的最大尺寸(最大字节数,文件上传用)

struts.multipart.parser
The org.apache.struts2.dispatcher.multipart.MultiPartRequest parser implementation for a multipart request (file upload)
专为multipart请求信息使用的org.apache.struts2.dispatcher.multipart.MultiPartRequest解析器接口(文件上传用)
该属性指定处理multipart/form-data的MIME类型(文件上传)请求的框架,该属性支持cos、pell和jakarta等属性值,即分别对应使用cos的文件上传框架、pell上传及common-fileupload文件上传框架。该属性的默认值为jakarta。

struts.multipart.saveDir
The directory to use for storing uploaded files
设置存储上传文件的目录夹,默认值是javax.servlet.context.tempdir。

struts.objectFactory
The com.opensymphony.xwork2.ObjectFactory implementation class
com.opensymphony.xwork2.ObjectFactory接口(spring)
指定Struts 2默认的ObjectFactory Bean,该属性默认值是spring。

struts.objectFactory.spring.autoWire
Whether Spring should autoWire or not
是否自动绑定Spring

struts.objectFactory.spring.useClassCache
Whether Spring should use its class cache or not
该属性指定整合Spring框架时,是否缓存Bean实例,该属性只允许使用true和false两个属性值,它的默认值是true。通常不建议修改该属性值。

struts.objectTypeDeterminer
The com.opensymphony.xwork2.util.ObjectTypeDeterminer implementation class
com.opensymphony.xwork2.util.ObjectTypeDeterminer接口
该属性指定Struts 2的类型检测机制,通常支持tiger和notiger两个属性值。

struts.serve.static.browserCache
If static content served by the Struts filter should set browser caching header properties or not
是否struts过滤器中提供的静态内容应该被浏览器缓存在头部属性中。当应用处于开发阶段时,我们希望每次请求都获得服务器的最新响应,则可设置该属性为false。

struts.serve.static
Whether the Struts filter should serve static content or not
是否struts过滤器应该提供静态内容

struts.tag.altSyntax
Whether to use the alterative syntax for the tags or not 
是否可以用替代的语法替代tags

struts.ui.templateDir
The directory containing UI templates
UI templates的目录夹

struts.ui.theme
The default UI template theme
默认的UI template主题

struts.url.http.port
The HTTP port used by Struts URLs
设置http端口

struts.url.https.port
The HTTPS port used by Struts URLs
设置https端口

struts.url.includeParams
The default includeParams method to generate Struts URLs
在url中产生 默认的includeParams

struts.velocity.configfile
The Velocity configuration file path
velocity配置文件路径

struts.velocity.contexts
List of Velocity context names
velocity的context列表

struts.velocity.manager.classname
org.apache.struts2.views.velocity.VelocityManager implementation class
org.apache.struts2.views.velocity.VelocityManager接口名

struts.velocity.toolboxlocation
The location of the Velocity toolbox
velocity工具盒的位置

struts.xslt.nocache
Whether or not XSLT templates should not be cached
是否XSLT模版应该被缓存
分享到:
评论

相关推荐

    struts2 配置文件

    ### Struts2 配置文件详解 #### 一、引言 在Struts2框架的应用开发过程中,配置文件起到了至关重要的作用。Struts2主要依赖于两种基于XML的配置文件:`web.xml` 和 `struts-config.xml`(通常命名为 `struts.xml`)...

    struts2配置文件加载顺序

    1. **struts-default.xml**:这是Struts2的核心配置文件,位于`struts2-core.jar`库的`/org/apache/struts2/defaults`包内。它包含了框架的基本设置,如拦截器栈、默认Action配置等。 2. **struts-plugin.xml**:这...

    ·Struts2配置文件介绍 超级详细

    ### Struts2配置文件介绍 #### 一、Struts2的核心配置文件 在Struts2框架中,有多个重要的配置文件用于控制应用的行为与结构,其中最核心的是`struts.xml`文件。此外还包括`web.xml`、`struts.properties`、`...

    Struts2 配置文件

    配置SSH框架时关于Struts2的配置文件

    Struts 2 配置文件

    Struts 2 配置文件解析与深度剖析 在Java Web开发领域,Struts 2 框架作为MVC(Model-View-Controller)架构模式的杰出代表,以其强大的功能和灵活的配置赢得了广大开发者的青睐。Struts 2 的核心配置文件struts....

    struts2配置文件详细说明

    配置文件在Struts2中起着至关重要的作用,它定义了框架的行为、动作映射、拦截器和其他关键设置。以下是Struts2配置文件的一些核心元素和属性的详细说明: 1. **配置文件结构**: Struts2的配置通常存储在一个名为...

    struts2配置文件以及代码示例

    ### Struts2配置文件及其代码示例解析 #### 一、Struts2概述 Struts2是一个基于MVC模式的开源Web应用框架,它继承了Struts1的优点,并且进行了大量的改进,支持拦截器、结果类型、动态方法调用等功能。在Struts2中...

    struts2配置文件改变位置问题

    在Struts2中,`struts.xml`文件是核心配置文件,它定义了动作、结果、拦截器等关键组件。在默认情况下,`struts.xml`通常位于`src/main/resources`或在Web应用中是`WEB-INF/classes`目录下。 在描述的问题中,...

    struts2配置文件传值中文乱码

    本文将围绕“Struts2配置文件传值中文乱码”这一主题,深入探讨其成因、解决方案以及相关的配置细节,旨在帮助开发者有效解决中文乱码问题,提升用户体验。 ### Struts2框架简介 Struts2是Apache组织下的一个开源...

    struts2配置文件详解

    ### Struts2配置文件详解 #### 一、引言 在Java Web开发中,Struts2框架因其灵活性和强大的功能而被广泛采用。Struts2框架的配置主要通过多个XML文件来实现,这些配置文件定义了应用程序的行为和结构。本文将详细...

    STRUTS2 配置文件

    一份基于.do拦截的struts2配置文件

    Struts2 配置文件手册

    配置文件在Struts2框架中起着至关重要的作用,它们定义了框架的行为、拦截器、对象工厂以及各种组件的配置。下面将详细介绍Struts2配置文件中的关键元素。 1) **struts-default.xml**: 这是Struts2框架默认加载的...

Global site tag (gtag.js) - Google Analytics