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

指定多个配置文件

  - 在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>org.struts</groupId>
<artifactId>Struts2-MultipleProfiles</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Struts2-MultipleProfiles Maven Webapp</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<struts.version>2.5.10</struts.version>
</properties> <dependencies>
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- struts2 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts.version}</version>
</dependency>
</dependencies> <build>
<finalName>Struts2-MultipleProfiles</finalName>
</build> </project>

3.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<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"> <filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>

4.HelloAction.java

package org.struts.action;

import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	@Override
public String execute() throws Exception { return SUCCESS; } }

5.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> <include file="helloworld.xml"/> </struts>

6.helloworld.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="org.struts.action.HelloAction">
<result>/index.jsp</result>
</action>
</package> </struts>

7.index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>指定多个配置文件测试</title>
</head>
<body>
指定多个配置文件测试成功
</body>
</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. L#中 int.TryParse 有问题

    今天发现了一个 L# 的异常..因此记录一下 List<string> strList = new List<string>(); ; i<; ++i) { ; j< ...

  2. javascript提示框,随着鼠标移动

    原文发布时间为:2009-04-23 -- 来源于本人的百度文章 [由搬家工具导入] <html><script type="text/javascript"&g ...

  3. [翻译]现代Linux系统上的栈溢出攻击【转】

    转自:http://www.codeweblog.com/%E7%BF%BB%E8%AF%91-%E7%8E%B0%E4%BB%A3linux%E7%B3%BB%E7%BB%9F%E4%B8%8A%E ...

  4. 00.mp4v2工具的用法

    1.交叉编译mp4v2库# ./configure --prefix=/usr/local/mp4v2-2.0.0 --host=arm-hisiv300-linux  CC=arm-hisiv300 ...

  5. fprintf与fscanf

    #include <stdio.h> int main() { //printf("Please input the value a:\n"); 等于下一句 fprin ...

  6. LeetCode OJ-- Insertion Sort List **

    https://oj.leetcode.com/problems/insertion-sort-list/ 链表实现插入排序 首先插入排序是指: a b c d e g m 对b也就是第二个位置选做元 ...

  7. 牛客网 牛客小白月赛2 H.武-最短路(Dijkstra)

    H.武 链接:https://www.nowcoder.com/acm/contest/86/H 这个题写的有点想发脾气,自己的板子垃圾了,这个题要用优先队列优化版的迪杰斯特拉的板子才可以过,但是自己 ...

  8. 牛客网 牛客小白月赛1 I.あなたの蛙が帰っています-卡特兰数,组合数阶乘逆元快速幂

    I.あなたの蛙が帰っています   链接:https://www.nowcoder.com/acm/contest/85/I来源:牛客网     这个题有点意思,是卡特兰数,自行百度就可以.卡特兰数用处 ...

  9. VS2017使用

    1. 用了一段时间的layui,发现官网的升级的功能很好用,于是把自己本地项目的layui升级到的高版本.按照官网上的代码几乎一模一样,但是功能就是出不来,之后发现本地虽然是高版本但是生成的脚本依然是 ...

  10. windows 下使用github客户端报错:Failed to publish this branch

    在windows系统下使用github客户端同步的时候报错“Failed to publish this branch”,查找原因,发现结果是安装vscode的时候没有检查到git,然后安装git后库 ...