struts.xml 是我们在开发中利用率最高的文件,也是 Struts2 中最重要的配置文件。
分别介绍一下几个 struts.xml 中常用到的标签
1
1
1
1 、 <include>
<include>
<include>
<include>
利用 include 标签,可以将一个 struts.xml 配置文件分割成多个配置文件,然后在 struts.xm l
中使用 <include> 标签引入其他配置文件。
比如一个网上购物程序,可以把用户配置、商品配置、订单配置分别放在 3 个配置文 件
user.xml 、 goods.xml 和 order.xml 中,然后在 struts.xml 中将这 3 个配置文件引入:
struts.xml :
01 <? xml version ="1.0" encoding ="UTF-8"?>
02 <!DOCTYPE struts PUBLIC
03 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
04 " http://struts.apache.org/dtds/struts-2.0.dtd ">
05
06
< struts
>
07 < include file ="user.xml"/>
08 < include file ="goods.xml"/>
09 < include file ="order.xml"/>
10
</ struts
>
user.xml :
01 <? xml version ="1.0" encoding ="UTF-8"?>
02 <!DOCTYPE struts PUBLIC
03 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
04 " http://struts.apache.org/dtds/struts-2.0.dtd ">
05
06
< struts
>
07 < package name ="wwfy" extends ="struts-default">
08 < action name ="login" class ="wwfy.user.LoginAction">
09
<!-- 省略 Action 其他配置 -->
10 </ action >
11 < action name ="logout" class ="wwfy.user.LogoutAction">
12
<!-- 省略 Action 其他配置 -->
13 </ action >
14 </ package >
15
</ struts
>
评论0
最新资源