© 版权声明:本文为博主原创文章,转载请注明出处

指定多个配置文件

  - 在Struts2配置文件中使用include可指定多个配置文件

实例

1.项目结构

2.pom.xml

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3.  
  4. <modelVersion>4.0.0</modelVersion>
  5.  
  6. <groupId>org.struts</groupId>
  7. <artifactId>Struts2-MultipleProfiles</artifactId>
  8. <packaging>war</packaging>
  9. <version>0.0.1-SNAPSHOT</version>
  10. <name>Struts2-MultipleProfiles Maven Webapp</name>
  11. <url>http://maven.apache.org</url>
  12.  
  13. <properties>
  14. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  15. <struts.version>2.5.10</struts.version>
  16. </properties>
  17.  
  18. <dependencies>
  19. <!-- junit -->
  20. <dependency>
  21. <groupId>junit</groupId>
  22. <artifactId>junit</artifactId>
  23. <version>4.12</version>
  24. <scope>test</scope>
  25. </dependency>
  26. <!-- struts2 -->
  27. <dependency>
  28. <groupId>org.apache.struts</groupId>
  29. <artifactId>struts2-core</artifactId>
  30. <version>${struts.version}</version>
  31. </dependency>
  32. </dependencies>
  33.  
  34. <build>
  35. <finalName>Struts2-MultipleProfiles</finalName>
  36. </build>
  37.  
  38. </project>

3.web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://java.sun.com/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  5. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  6. version="3.0" metadata-complete="true">
  7.  
  8. <filter>
  9. <filter-name>struts</filter-name>
  10. <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
  11. </filter>
  12. <filter-mapping>
  13. <filter-name>struts</filter-name>
  14. <url-pattern>/*</url-pattern>
  15. </filter-mapping>
  16.  
  17. </web-app>

4.HelloAction.java

  1. package org.struts.action;
  2.  
  3. import com.opensymphony.xwork2.ActionSupport;
  4.  
  5. public class HelloAction extends ActionSupport {
  6.  
  7. private static final long serialVersionUID = 1L;
  8.  
  9. @Override
  10. public String execute() throws Exception {
  11.  
  12. return SUCCESS;
  13.  
  14. }
  15.  
  16. }

5.struts.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
  4. "http://struts.apache.org/dtds/struts-2.5.dtd">
  5. <struts>
  6.  
  7. <include file="helloworld.xml"/>
  8.  
  9. </struts>

6.helloworld.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
  4. "http://struts.apache.org/dtds/struts-2.5.dtd">
  5. <struts>
  6.  
  7. <package name="hello" extends="struts-default" namespace="/">
  8. <action name="hello" class="org.struts.action.HelloAction">
  9. <result>/index.jsp</result>
  10. </action>
  11. </package>
  12.  
  13. </struts>

7.index.jsp

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>指定多个配置文件测试</title>
  8. </head>
  9. <body>
  10. 指定多个配置文件测试成功
  11. </body>
  12. </html>

8.效果预览

参考:http://www.imooc.com/video/9000

Struts2学习五----------指定多个配置文件的更多相关文章

  1. Struts2 学习记录-1--Struts2中的配置文件

    目录 1. web.xml 2. struts.xml 3. struts.properties文件 4.注解式开发 5.与Spring框架集成的配置 主要涉及3个配置文件:web.xml.strut ...

  2. 《struts2》:指定多个配置文件和默认Action

    转载:http://m.blog.csdn.net/article/details?id=51212968

  3. Struts2学习笔记:DMI,多个配置文件,默认Action,后缀

    动态方法调用有三种方法: 1.同一Action多次映射,每个action标签的method对应要调用的方法. 当要调用的方法多了就会增加struts.xml文件的复杂性. 2.struts.Dynam ...

  4. Struts2学习笔记(三)——Action详解

    Action是用于处理请求操作的,它是由StrutsPrepareAndExceuteFilter分发过来的. 1.Action的创建方式 1) POJO类(PlainOldJavaObjects简单 ...

  5. Struts2学习笔记整理(一)

    最近在学习框架,很多人建议我直接学SSM,SSM看了一段时间后发现很多东西虽然可以用了,但是并不是很了解,所以我打算重新来过.从SSH开始学习,前面已经大致的学习了Hibernate,对于Hibern ...

  6. Struts2学习(一)————Struts2入门

    首先推荐一本书,虽然我还没看过,但是我以后肯定会看的,<Struts+技术内幕>提取密码:kg6w .现在只是停留在会使用struts2的层次,自己也想继续深入研究,但是感觉自己的知识面还 ...

  7. Struts2 学习笔记(概述)

    Struts2 学习笔记 2015年3月7日11:02:55 MVC思想 Strust2的MVC对应关系如下: 在MVC三个模块当中,struts2对应关系如下: Model: 负责封装应用的状态,并 ...

  8. NoSQL之【MongoDB】学习(三):配置文件说明

    摘要: 继上一篇NoSQL之[MongoDB]学习(一):安装说明 之后,知道了如何安装和启动MongoDB,现在对启动时指定的配置文件(mongodb.conf)进行说明,详情请见官方. 启动Mon ...

  9. 【Struts2学习笔记-3】常量配置

    Struts2常量 配置Struts2常量值有3个地方,1)在struts.properties文件中配置常量:2)在web.xml文件中配置FileterDispatcher指定初始化参数来配置常量 ...

随机推荐

  1. bzoj 2563 贪心 思想

    BZOJ2563阿狸和桃子的游戏   2563: 阿狸和桃子的游戏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 952  Solved: 682[Su ...

  2. linux下头文件

    aio.h 异步I/Oassert.h 验证程序断言complex 复数类complex.h 复数处理cpio.h cpio归档值ctype.h 字符类型dirent.h 目录项,opendir(), ...

  3. nodeJS学习(4)--- webstorm/...开发 NodeJS 项目-节1

    前提: 已安装好 IDE ,eg:webstorm/IDEA 2016.3 & 2017.1 nodeJS(含 npm 及 相应的模板等) 要用 webstorm 开发 NodeJS项目(we ...

  4. T-SQL百万记录中分组取最大值方法ROW_NUMBER() OVER()

    SELECT SysUserID, UserID, ROW_NUMBER() OVER(PARTITION BY UserID ORDER BY AddTime DESC) AS nums AND S ...

  5. linux之eval

    1. eval command-line 其中command-line是在终端上键入的一条普通命令行.然而当在它前面放上eval时,其结果是shell在执行命令行之前扫描它两次.如: pipe=&qu ...

  6. JS - caller,callee,call,apply [transfer] aA ==> apply uses an array [] as the second argument. call uses different argument.

    在提到上述的概念之前,首先想说说javascript中函数的隐含参数:arguments Arguments : 该对象代表正在执行的函数和调用它的函数的参数. [function.]argument ...

  7. java网络编程(二)

    客户端程序: package net; import java.io.OutputStream; import java.net.Socket; /** * Created by hu on 2015 ...

  8. linux内核情景分析之强制性调度

    从系统调用返回到用户空间是否调度,从ret_with_reschedule可看出,是否真正调度,取决于当前进程的pcb中的need_resched是否设置为1,那如何设置为1取决于以下几种情况: 时间 ...

  9. interview ms1 N_Dorm

    判断是否为n回文,比如 a b a 是1 回文, abcdab是2回文. 输入: abcabc|3 这种格式,输出true or false #include <iostream> #in ...

  10. querySelector和getElementById之间的区别

    一.概述 今天在看js的时候发现里面的代码基本上都是用querySelector()和querySelectorAll()来获取元素,就有点疑惑为什么不用getElementById(),可能也是因为 ...