引入多个配置文件

在Struts2配置文件中使用include可引入多个配置文件。

项目实例

1.项目结构

2、pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ray</groupId>
  <artifactId>struts2Test</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>struts2Test Maven Webapp</name>
  <url>http://maven.apache.org</url>

  <dependencies>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-core -->
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-core</artifactId>
      <version>2.5.16</version>
    </dependency>

  </dependencies>

  <build>
    <finalName>struts2Test</finalName>
  </build>

</project>

3、web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0" metadata-complete="true">
  <display-name>Archetype Created Web Application</display-name>

  <!-- 过滤所有请求交给Struts2处理 -->
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
      org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
  </filter>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

</web-app>

4、HelloWorldAction.java

package com.ray.action;

import com.opensymphony.xwork2.ActionSupport;

/**
 * Created by Ray on 2018/3/26 0026.
 **/
public class HelloWorldAction extends ActionSupport {

    /**
    * @Author: Ray
    * @Date: 2018/3/26 0026
    * @Description: Struts2默认执行的方法
    * @Return: SUCCESS
    */
    @Override
    public String execute() throws Exception {
        return super.execute();
    }
}

5、fourth-struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">

<struts>

    <package name="hello" extends="struts-default" namespace="/">
        <action name="hello" class="com.ray.action.HelloWorldAction">
            <result>/hello.jsp</result>
        </action>
    </package>
</struts>

6、struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">

<struts>

    <package name="default" namespace="/" extends="struts-default">

        <action name="helloWorld" class="com.ray.action.HelloWorldAction">
            <result name="success">/success.jsp</result>
        </action>
    </package>

    <include file="second-struts.xml"/>
    <include file="third-struts.xml"/>
    <include file="fourth-struts.xml"/>
</struts>

7、hello.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>指定多个配置文件测试</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
    指定多个配置文件测试成功
</body>
</html>

8、页面效果

访问:http://localhost:8080/struts2Test/hello.action

ok!

第四篇——Struts2的引入多个配置文件的更多相关文章

  1. 深入理解javascript作用域系列第四篇——块作用域

    × 目录 [1]let [2]const [3]try 前面的话 尽管函数作用域是最常见的作用域单元,也是现行大多数javascript最普遍的设计方法,但其他类型的作用域单元也是存在的,并且通过使用 ...

  2. C++第四篇--重载_指针_引用

    C++第四篇--重载_指针_引用 1. 基础知识 重载:函数名相同,根据参数不同(类型.数量.顺序不同)调用同名函数 指针和引用:引用就是别名,引用时必须初始化,引用你定义的变量. int a; in ...

  3. 深入理解javascript作用域系列第四篇

    前面的话 尽管函数作用域是最常见的作用域单元,也是现行大多数javascript最普遍的设计方法,但其他类型的作用域单元也是存在的,并且通过使用其他类型的作用域单元甚至可以实现维护起来更加优秀.简洁的 ...

  4. 【block第四篇】实现

    -------------------------------------------欢迎查看block连载博客[专栏]--------------------------------------[b ...

  5. SpringBoot第二十四篇:应用监控之Admin

    作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/11457867.html 版权声明:本文为博主原创文章,转载请附上博文链接! 引言   前一章(S ...

  6. VueRouter爬坑第四篇-命名路由、编程式导航

    VueRouter系列的文章示例编写时,项目是使用vue-cli脚手架搭建. 项目搭建的步骤和项目目录专门写了一篇文章:点击这里进行传送 后续VueRouter系列的文章的示例编写均基于该项目环境. ...

  7. Spring Cloud第十四篇 | Api网关Zuul

    ​ 本文是Spring Cloud专栏的第十四篇文章,了解前十三篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring C ...

  8. 从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点)

    从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...

  9. 第四篇 Entity Framework Plus 之 Batch Operations

    用 Entity Framework  进行 增,删,改.都是基于Model进行的,且Model都是有状态追踪的.这样Entity Framework才能正常增,删,改. 有时候,要根据某个字段,批量 ...

随机推荐

  1. 转载:VOC2007数据集制作

    转载自:https://blog.csdn.net/gaohuazhao/article/details/60871886 另外,可参考:https://blog.csdn.net/dcxhun3/a ...

  2. 【消灭代办】第4周 - Echarts在移动端的各种填坑姿势

    啊呀呀呀呀...... 2018-12-03 代办一:坐标指示器相关问题: 见另一篇 第二问:https://www.cnblogs.com/padding1015/p/9936533.html 20 ...

  3. GO语言-基础语法:变量定义

    package main import ( "fmt" ) //不在函数内的变量,属于包内的变量.不能使用":="进行定义和赋值 var ( bb = cc = ...

  4. lis最长上升子序列

    因为是最长上升的,可以用一个数组储存上升的序列,如果后一个数字比数组的最大数字还大,就加到末尾去,如果不大于,那么就可以把这个数组中比他大的数字替换掉,因为如果数字更小,后面上升序列更长的可能性更大, ...

  5. hibernate11--Criteria查询

    public class EmpTest { Session session =null; Transaction transaction=null; @Before public void befo ...

  6. date格式互转

    +"%Y/%m/%d-%H:%M:%S" date -d "2017/11/21 17:02:09" +%s

  7. 简述TCP三次握手和四次挥手过程

    TCP握手协议 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接.第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器确 ...

  8. Unity 为队伍设置不同颜色的shader

    在魔兽争霸等一些游戏中,我们通过模型的颜色就能很轻松的区分队伍,如下:   实现的方法有很多,比如: 1,为不同队伍各出一张不同颜色的贴图(Hmmm,war3有的地图可以容纳12只队伍,美术大大们会很 ...

  9. C语言定义的操作mysql数据库的接口

    编写的环境:centos7系统下,对mysql的衍生mariadb进行数据库的操作,包含设置访问数据库的参数,查询数据库和增删改数据库的三个功能.对于查询数据库,我这里允许不返回查询结果,用于判断查询 ...

  10. python语法_注释

    #加需要注释的内容,#号后面的单行注释 #这一段注释 左右各三个注释单引号或者双引号 中间的内容为注释,可以包含多行 '''这一段注释''' """这一段注释" ...