第四篇——Struts2的引入多个配置文件
引入多个配置文件
在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的引入多个配置文件的更多相关文章
- 深入理解javascript作用域系列第四篇——块作用域
× 目录 [1]let [2]const [3]try 前面的话 尽管函数作用域是最常见的作用域单元,也是现行大多数javascript最普遍的设计方法,但其他类型的作用域单元也是存在的,并且通过使用 ...
- C++第四篇--重载_指针_引用
C++第四篇--重载_指针_引用 1. 基础知识 重载:函数名相同,根据参数不同(类型.数量.顺序不同)调用同名函数 指针和引用:引用就是别名,引用时必须初始化,引用你定义的变量. int a; in ...
- 深入理解javascript作用域系列第四篇
前面的话 尽管函数作用域是最常见的作用域单元,也是现行大多数javascript最普遍的设计方法,但其他类型的作用域单元也是存在的,并且通过使用其他类型的作用域单元甚至可以实现维护起来更加优秀.简洁的 ...
- 【block第四篇】实现
-------------------------------------------欢迎查看block连载博客[专栏]--------------------------------------[b ...
- SpringBoot第二十四篇:应用监控之Admin
作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/11457867.html 版权声明:本文为博主原创文章,转载请附上博文链接! 引言 前一章(S ...
- VueRouter爬坑第四篇-命名路由、编程式导航
VueRouter系列的文章示例编写时,项目是使用vue-cli脚手架搭建. 项目搭建的步骤和项目目录专门写了一篇文章:点击这里进行传送 后续VueRouter系列的文章的示例编写均基于该项目环境. ...
- Spring Cloud第十四篇 | Api网关Zuul
本文是Spring Cloud专栏的第十四篇文章,了解前十三篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring C ...
- 从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点)
从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...
- 第四篇 Entity Framework Plus 之 Batch Operations
用 Entity Framework 进行 增,删,改.都是基于Model进行的,且Model都是有状态追踪的.这样Entity Framework才能正常增,删,改. 有时候,要根据某个字段,批量 ...
随机推荐
- C# 获取对象 大小 Marshal.SizeOf (sizeof 只能在不安全的上下文中使用)
C# 能否获取一个对象所占内存的大小? 今日,在项目重构的时候忽然想到一个问题,一个类哪些成员的增加,会影响一个类所占内存的大小?C#有没有办法知道一个对象占多少内存呢? 第一个问题:很快想到是类的非 ...
- 媳妇要转java开发,我该怎么办?
我是一名5年的java开发者,媳妇是一个5年的软件实施工程师,我们结婚快一年了,这几天她突然对我说,她想转java开发,让我辅导她学习java,我该怎么弄,我心底是不愿意她转开发的,毕竟她年龄也不小了 ...
- python str byte 转换
# bytes object b = b"example" # str object s = "example" # str to bytes bytes(s, ...
- 【netcore基础】CentOS 7.6.1810 搭建.net core 2.1 linux 运行环境 nginx反向代理 supervisor配置自启动
之前写过一篇Ubuntu的环境搭建博客,感觉一些配置大同小异,这里重点记录下 nginx 作为静态 angular 项目文件服务器的配置 参考链接 [netcore基础]ubuntu 16.04 搭建 ...
- game 角色相关记录
GameServer启动 (role, misc, mail, offline)从共享内存中加载数据到m_mBlob中如果共享内存没有则从DB加载 主要是修改了同步共享内存,共享内存同步数据库{//r ...
- 八、Sql Server 基础培训《进度8-查询多种写法》(实际操作)
知识点: 假设学生表.班级表.年级表 学生表(student) 内码 学生姓名 班级内码 001 张三 1002 002 李四 1002 003 王五 1003 004 钱六 1001 班级表(cla ...
- 【转载】C++中替代sprintf的std::ostringstream输出流详解
一.简单介绍 ostringstream是C++的一个字符集操作模板类,定义在sstream.h头文件中.ostringstream类通常用于执行C风格的串流的输出操作,格式化字符串,避免申请大量的缓 ...
- Spring MVC 知识点整理
extend:http://www.jianshu.com/p/bef0e52067d2 1. Redis 存储方式 Redis存储机制分成两种Snapshot 和 AOF.无论是那种机制,Redis ...
- Power BI数据网关
前言 你的组织中的用户可以访问本地数据(他们已经具有该数据的访问授权),但在这些用户可以连接到你的本地数据源之前,需要安装和配置本地数据网关. 该网关便于云中的用户与你的本地数据源相互进行快速安全 ...
- 一次完整的从webshell到域控的探索之路
前言 内网渗透测试资料基本上都是很多大牛的文章告诉我们思路如何,但是对于我等小菜一直是云里雾里. 于是使用什么样的工具才内网才能畅通无阻,成了大家一直以来的渴求. 今天小菜我本着所有师傅们无私分享的精 ...