第四篇——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才能正常增,删,改. 有时候,要根据某个字段,批量 ...
随机推荐
- 认识 SSH 密钥对
SSH 密钥对是阿里云为您提供的新的远程登录 ECS 实例的认证方式. 相较于传统的用户名和密码认证方式,SSH 密钥对有以下特点: 仅适用于 Linux 实例: SSH 密钥对登录认证更为安全可靠: ...
- 【学习】C++异常处理,exception
try.catch try { ... }中的语句按顺序执行,突然遇到错误了,则捕获,catch. try中语句执行到最后可以加一条语句,打印出,程序成功运行. catch(const .....e) ...
- 新唐N32905U1DN开发教程:MDK环境下工程搭建(官方提供的固件库)(转)
前言:新唐N32905U1DN单片机不支持用户将程序烧录到内部FLASH,必须外挂FLASH存储用户程序,可以是SPI FLASH.NAND FLASH.SD卡.用户采用裸机开发的方式可使用官方提供的 ...
- IntelliJ IDEA 2018.3.2无法正常输入字符问题解决方案
昨天升级IDEA的版本到2018.3.2,今天打开项目发现只要在代码编辑器输入字符(英文.符号或中文等)都会立刻被强制删除,造成一个无法正常输入的现象(回车换行可以).仔细观察这种想象后发有可能是代码 ...
- D - Bridge
n people wish to cross a bridge at night. A group of at most two people may cross at any time, and e ...
- poj 1269
水题.判断两条直线位置关系. 考虑平行的情况,那么 四边形的面积会相等,重合的话,四边形的面积相等且为0. 除去这两种就一定有交点. #include <cstdio> #include ...
- linux的基本操作(LAMP环境搭建)
LAMP 环境搭建 经过前部分章节的学习,你已经掌握了linux的基础知识了.但是想成为一名系统管理员恐怕还有点难度,因为好多单位招聘这个职位的时候都要求有一定的工作经验.然而真正的经验一天两天是学不 ...
- common lisp里的几个操作符
setf 赋值操作符,定义一个全局变量.返回值是最后一个赋值的结果. let 局部变量操作符.let表达式有两部分组成.第一部分是任意多的变量赋值,他们被包裹在一个()中,第二部分是任意数量的表示式 ...
- CPanel/服务器文件及目录
cPanel服务器默认的各主要目录及配置文件的路径.cPanel服务器很多配置文件的路径和通常情况下安装LAMP的不同,另外还有很多是属于cPanel面板自己的配置文件. 目录 1 Apache 2 ...
- 【Swing程序设计/常用面板】
面板也是一个Swing容器,可以作为容器容纳其他组件,但是它必须要被添加到其他容器中.Swing常见的面板是JPanel面板和JScrollPanel面板. JPanel面板可以聚集一些组件来布局. ...