Struts 2自带有“包含文件”功能,包含多个Struts配置文件合并为一个单元。
单个Struts配置文件
让我们来看看一个糟糕的 Struts 2 配置示例。

struts.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="default" namespace="/" extends="struts-default">
</package> <package name="audit" namespace="/audit" extends="struts-default">
<action name="WelcomeAudit">
<result>pages/welcome_audit.jsp</result>
</action>
</package> <package name="user" namespace="/user" extends="struts-default">
<action name="WelcomeUser">
<result>pages/welcome_user.jsp</result>
</action>
</package> </struts> 

在上面的Struts配置文件中,组织所有“用户”和“审核”配置设置在一个文件中,这不是建议的,必须回避。应该打破这种形式,而将struts.xml文件分成更小的模块相关的部分。

多个Struts配置文件
在Struts2,应该给每个模块一个Struts配置文件。在这种情况下,可以创建三个文件:
  1. audit-struts.xml – 将所有审计模块设置在这里。
  2. user-struts.xml – 将所有用户模块设置在这里。
  3. struts.xml – 默认设置,包含 struts-audit.xml 和 Struts-user.xml 两个文件。

struts-audit.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="audit" namespace="/audit" extends="struts-default">
<action name="WelcomeAudit">
<result>pages/welcome_audit.jsp</result>
</action>
</package> </struts>

struts-user.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="user" namespace="/user" extends="struts-default">
<action name="WelcomeUser">
<result>pages/welcome_user.jsp</result>
</action>
</package> </struts>

struts.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="default" namespace="/" extends="struts-default">
</package> <include file="conf/user-struts.xml"></include>
<include file="conf/audit-struts.xml"></include> </struts>

现在文件夹结构看起来如下:

 

标签:Struts2    include    包含    配置文件

本站文章除注明转载外,均为本站原创或编译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动共创优秀实例教程
转载请注明:文章转载自:易百教程 [http:/www.yiibai.com]
本文标题:Struts2 include(包含)多个配置文件
本文地址:http://www.yiibai.com/struts_2/struts-2-include-multiple-struts-configuration-files.html

Struts2 include(包含)多个配置文件的更多相关文章

  1. struts2.0中struts.xml配置文件详解

    先来展示一个配置文件 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration ...

  2. struts2:多模块多配置文件开发

    struts2支持多模块多配置文件开发.下面是一个仅包含两个模块的示范程序,包括财务.仓库模块.它们都有一个“caiwu“的Action,在各自的命名空间下:还有一个从财务转向到仓库的Action. ...

  3. Apache下开启SSI配置使html支持include包含

    写页面的同学通常会遇到这样的烦恼,就是页面上的 html 标签越来越多的时候,寻找指定的部分就会很困难,那么能不能像 javascript 一样写在不同的文件中引入呢?答案是有的,apache 能做到 ...

  4. Apache下开启SSI配置,使html支持include包含

    有的时候,我们的页面有公共的导航栏navbar,公共的脚注footer,那么我们就想把这些公共部分独立成一个html文件,在要引用的地方像引用js,css一样,给包含进来. Apache下开启SSI配 ...

  5. include包含头文件的语句中,双引号和尖括号的区别是什么?

    include包含头文件的语句中,双引号和尖括号的区别是什么?  #include <> 格式:引用标准库头文件,编译器从标准库目录开始搜索 尖括号表示只在系统默认目录或者括号内的路径查找 ...

  6. struts2的两个核心配置文件

    struts2的两个核心配置文件,即:struts.default.xml和struts.properties A,位置:都在struts2-core-version.jar文件中 B,作用,stru ...

  7. C++中#include包含头文件带 .h 和不带 .h 的区别

    C++中#include包含头文件带 .h 和不带 .h 的区别? 如 #include <iostream> 和 #include <iostream.h> 包含的东西有哪些 ...

  8. include包含头文件的语句中,双引号和尖括号的区别

    include包含头文件的语句中,双引号和尖括号的区别   #include <>格式:引用标准库头文件,编译器从标准库目录开始搜索 #incluce ""格式:引用非 ...

  9. asp.net使用include包含文件

    么?用asp.net使用include包含文件?……有必要吗?使用“用户控件”不是更好吗? 当然,绝大多数情况下,用户控件都能解决问题.但若要在用户控件中需包含其他公用块,即使用用户控件嵌套,老是出问 ...

随机推荐

  1. 动态更新echarts k线图数据 通过websocket取数据

    1.加载插件,实例化chart.2.链接websocket3.接收数据,处理数据,调用chart的实例,不断更新数据<!DOCTYPE html><html><head ...

  2. MVC开发模式与javaEE三层架构

    1.MVC开发模式 1. M:Model,模型.JavaBean        * 完成具体的业务操作,如:查询数据库,封装对象2. V:View,视图.JSP        * 展示数据3. C:C ...

  3. 深入理解计算机系统项目之 Shell Lab

    博客中的文章均为meelo原创,请务必以链接形式注明本文地址 Shell Lab是CMU计算机系统入门课程的一个实验.在这个实验里你需要实现一个shell,shell是用户与计算机的交互界面.普通意义 ...

  4. fastdfs5.10 centos6.9 安装配置

    下载相关软件 https://codeload.github.com/happyfish100/fastdfs/tar.gz/V5.10http://download.csdn.net/detail/ ...

  5. day4 作业计算器

    作业:计算器开发 (1)实现加减乘除及拓号优先级解析: (2)用户输入 1 - 2 * ( (60-30 +(-40/5) * (-9-2*5/-3 + 7 /3*99/4*2998 +10 * 56 ...

  6. matplotlib 练习

    官网 vamei的博客还是读了就秒懂,很妙, matplotlib核心剖析 官网翻译也不错,但缺少了 Logarithmic and other nonlinear axis对数等非线性轴  这一模块 ...

  7. ctime, atime与mtime释疑

    每个档案都有属性及内容.除了档案内容很重要外,时间标记也非常重要--系统管理员可以藉由时间标记进行备份.例行性检查:使用者可以从时间标记找出重要的档案,硬碟的I/O也依靠时间标记(time flag) ...

  8. lr_save_searched_string函数的使用介绍

    函数功能:在某一个字符缓冲区中搜索指定的字符串,并将搜到的字符串保存在参数中. 应用场合:可配合LoadRunner的关联功能,灵活获取服务器端返回的数据 举例:客服3.0工作流系统,工单处理每次都从 ...

  9. Centos7 ocsp功能验证

    转载:https://blog.csdn.net/tsh185/article/details/8107248 先按照Centos7创建CA和申请证书创建PKI所需要的文件 运行服务器端: opens ...

  10. 查看Android手机数据库

    有的时候,手机没有root,无法查看数据库,甚不方便,好在Github上有解决方案: Github地址:https://github.com/king1039/Android-Debug-Databa ...