J2EE系列之Struts2学习笔记(八)--struts.xml分模块配置
来源:互联网 发布:花生壳免费域名绑定ip 编辑:程序博客网 时间:2024/05/22 17:10
先来看一下上一篇博客中工程的配置文件:
这个文件中有两个包,也可以说是有两个模块。当一个工程比较大的时候,里面的模块可能会有几十甚至上百个,如果都这样写着struts.xml文件中,那么struts.xml难免就会非常的混乱。struts2提供了分模块配置方法。通过一个示例来看一下:
1.新建工程SecondLearnStruts2Chap02_04:假定这个工程下有两个大模块分别是车辆管理和资产管理。
2.在src目录下新建cheliang.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="cheliang" namespace="/cheliang" extends="struts-default"> <action name="cheliang" class="com.test.action.CheLiangAction"> <result name="success">${pageContext.request.contextPath}/success.jsp</result> </action> </package></struts>
新建zichan.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="zichan" namespace="/zichan" extends="struts-default"> <action name="zichan" class="com.test.action.ZiChanAction"> <result name="success">${pageContext.request.contextPath}/success.jsp</result> </action> </package></struts>
通过<include file="" ></include>标签把这两个配置文件包含在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> <include file="cheliang.xml"></include> <include file="zichan.xml"></include></struts>
这样我们就把车辆管理和资产管理两个模块的配置文件都配置到了struts.xml文件中。
3.新建CheLiangAction:
package com.test.action;import com.opensymphony.xwork2.ActionSupport;public class CheLiangAction extends ActionSupport{/** * */private static final long serialVersionUID = 1L;@Overridepublic String execute() throws Exception {System.out.println("执行了CheLiangAction的默认方法");return SUCCESS;}}
新建ZiChanAction:
package com.test.action;import com.opensymphony.xwork2.ActionSupport;public class ZiChanAction extends ActionSupport{/** * */private static final long serialVersionUID = 1L;@Overridepublic String execute() throws Exception {System.out.println("执行了ZiChanAction的默认方法");return SUCCESS;}}
运行程序:
控制台输出为:
程序运行成功了。
总结一下:这里通过<include file="" ></include>实现struts2工程的分模块配置。
0 0
- J2EE系列之Struts2学习笔记(八)--struts.xml分模块配置
- J2EE系列之Struts2学习笔记(七)--struts.xml配置
- J2EE系列之Struts2学习笔记(九)--使用通配符配置struts.xml文件
- J2EE系列之Struts2学习笔记(十一)--result配置
- J2EE系列之Struts2学习笔记(一)--Struts2安装与配置
- J2EE系列之Struts2学习笔记(十八)--Struts2国际化
- J2EE系列之MyBatis学习笔记(八)-- 杂项
- struts2 学习笔记之 struts.xml 配置解析
- J2EE Struts2 学习笔记003 ---- struts.xml 解析
- J2EE系列之MyBatis学习笔记(三)-- 使用XML配置SQL映射器
- J2EE系列之MyBatis学习笔记(二)-- mybatis配置
- struts2学习(二)struts.xml配置
- J2EE系列之Struts2学习笔记(十九)--Struts2验证框架(内置验证)
- J2EE系列之Struts2学习笔记(二十)--Struts2验证框架(自定义验证)
- J2EE系列之Struts2学习笔记(十六)--Struts2标签(数据标签、控制标签)
- J2EE系列之Struts2学习笔记(十七)--Struts2标签(界面标签、其他标签)
- J2EE系列之Struts2学习笔记(二十一)--Struts2文件上传
- J2EE系列之Struts2学习笔记(二十二)--Struts2多文件上传和文件下载
- Java虚拟机知识框架图
- 同步(Synchronous). VS 异步(Asynchronous).
- UWP:使用MediaPlayerElement实现媒体播放器
- jstl中对java map的应用
- 修改Oracle数据库表中的字段顺序
- J2EE系列之Struts2学习笔记(八)--struts.xml分模块配置
- 应用开发向轻量级转化,PWA能代表下一代APP趋势吗?
- php使用阿里大于短信平台发送验证码记录
- CentOS 6系统kvm虚拟机中配置桥接网络
- 全量数据同步与数据校验实践——应对百亿量级分库分表异构库迁移
- 微服务 Microservice
- 最长上升子序列
- 数据库
- pa乙级1056-1060