第四篇——Struts2的引入多个配置文件

原文链接: http://www.cnblogs.com/Remenber-Ray/p/8858045.html

引入多个配置文件

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


项目实例

1.项目结构

第四篇——Struts2的引入多个配置文件_第1张图片


2、pom.xml


  4.0.0
  com.ray
  struts2Test
  war
  1.0-SNAPSHOT
  struts2Test Maven Webapp
  http://maven.apache.org

  

    
      junit
      junit
      3.8.1
      test
    

    
    
      org.apache.struts
      struts2-core
      2.5.16
    


  

  
    struts2Test
  

3、web.xml


  Archetype Created Web Application

  
  
    struts2
    
      org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
    
  

  
    struts2
    /*
  

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







    
        
            /hello.jsp
        
    


6、struts.xml







    

        
            /success.jsp
        
    
    
    
    
    


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 + "/";
%>




    

    指定多个配置文件测试

    
    
    
    
    
    




    指定多个配置文件测试成功


8、页面效果

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

第四篇——Struts2的引入多个配置文件_第2张图片

ok!

转载于:https://www.cnblogs.com/Remenber-Ray/p/8858045.html

你可能感兴趣的:(第四篇——Struts2的引入多个配置文件)