zoukankan      html  css  js  c++  java
  • 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>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

  • 相关阅读:
    html固定宽度下拉框内容显示不全问题解决方法
    ORA-00918: column ambiguously defined
    LigerUI可编辑表格左下角出现白色小方块遮罩层问题解决办法
    Lombok简化Java代码的好工具
    PLSQL Developer连接不上64位Oracle 10g的解决办法
    Windows 2008安装Oracle10g提示操作系统版本检查未通过
    Windows2008安装WebSphere 6.1提示此安装程序不能在图形方式中运行
    LigerUI树节点选中之后节点背景太短
    javapms部署之后首页不能正常显示问题
    Oracle触发器给表自身的字段重新赋值出现ORA-04091异常
  • 原文地址:https://www.cnblogs.com/jinjiyese153/p/6873780.html
Copyright © 2011-2022 走看看