首页 技术 正文
技术 2022年11月8日
0 收藏 783 点赞 1,195 浏览 1928 个字

struts.xml文件中包含的配置信息,你将修改所采取的措施的开发。这个文件可以被用来覆盖默认设置的应用程序,例如struts.devMode=false和其他设置中定义的属性文件。这个文件可以创建文件夹下的WEB-INF/classes。

让我们一起来看看我们在struts.xml文件中创建Hello World的例子在前面的章节中解释。

<?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.devMode" value="true" />
<package name="helloworld" extends="struts-default"> <action name="hello"
class="com.yiibai.struts2.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
<-- more actions can be listed here --> </package>
<-- more packages can be listed here --></struts>

首先要注意的是DOCTYPE。所有的Struts配置文件中需要有正确的DOCTYPE,在我们的小例子所示。<struts>是根标记的元素,我们声明使用不同的包<package>标签。其中,<package>允许分离和模块化的配置。这是非常有用的,当你有一个大的项目,项目被划分成不同的模块。

再说了,如果项目有三个域名 – business_applicaiton,customer_application和staff_application,可以创建三个包,在适当的包装和存储相关的行动。包装标签具有以下属性:

属性 描述
name (required) The unique identifier for the package
extends Which package does this package extend from? By default, we use struts-default as the base package.
abstract If marked true, the package is not available for end user consumption.
namesapce Unique namespace for the actions

常量标签name和value属性将被用来覆盖default.properties中定义的属性,就像我们刚刚成立struts.devModeproperty。设置struts.devMode属性,让我们看到了更多的调试信息,日志文件中。

我们定义动作标记对应的每一个URL,我们想访问我们定义了一个类的execute()方法,将访问时,我们将访问相应的URL。
结果确定什么被返回到浏览器的一个动作后执行。从操作返回的字符串应该是一个结果的名称。结果如上配置的每次动作,或作为一个“全局”的结果,在包中的每一个动作可。结果有可选的名称和类型的属性。默认名称值是“成功”。

随着时间的推移,struts.xml文件可以做大,打破它包的模块化是一种方式,但Struts提供了另一种模块化的struts.xml文件。你可以将档案分割成多个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>
<include file="my-struts1.xml"/>
<include file="my-struts2.xml"/>
</struts>

我们还没有涉及到的其他配置文件是struts-default.xml中。这个文件包含了Struts标准配置设置,在你的项目的99.99%就不会碰这些设置。出于这个原因,我们不打算在这个文件太多的细节。如果有兴趣,不妨看看在default.properties文件中struts2的核心-2.2.3.jar文件。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844