---
title: "struts-config文件路径问题"
author: "cakin24"
date: "2017-10-26T21:26:03Z"
tags: []
categories: ["编程语言"]
slug: "struts-config"
draft: false
lastmod: "2017-10-26T21:26:03Z"
id: 2397758
url: "https://cakin24.iteye.com/blog/2397758"
---

一 介绍

struts-config文件路径，不一定非要放在/WEB-INF中，可以自己放。

 

二 修改方法

例如：struts-config放置路径如下截图

![](http://dl2.iteye.com/upload/attachment/0127/5593/f7176158-d36b-33fb-9cc7-3f83332f0eec.png)  
 

配置方法

&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;web-app xmlns="[http://java.sun.com/xml/ns/javaee"](http://java.sun.com/xml/ns/javaee%22); xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance"](http://www.w3.org/2001/XMLSchema-instance%22); version="2.5" xsi:schemaLocation="[http://java.sun.com/xml/ns/javaee](http://java.sun.com/xml/ns/javaee)[http://java.sun.com/xml/ns/javaee/web-app\_2\_5.xsd"](http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd%22);&gt;

  &lt;display-name /&gt;

  &lt;servlet&gt;

    &lt;servlet-name&gt;action&lt;/servlet-name&gt;

    &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;

    &lt;!-- 配置struts-config.xml --&gt;

    &lt;init-param&gt;

      &lt;param-name&gt;config&lt;/param-name&gt;

      &lt;param-value&gt;/WEB-INF/config/struts-config.xml&lt;/param-value&gt;

    &lt;/init-param&gt;

    &lt;init-param&gt;

      &lt;param-name&gt;debug&lt;/param-name&gt;

      &lt;param-value&gt;3&lt;/param-value&gt;

    &lt;/init-param&gt;

    &lt;init-param&gt;

      &lt;param-name&gt;detail&lt;/param-name&gt;

      &lt;param-value&gt;3&lt;/param-value&gt;

    &lt;/init-param&gt;

    &lt;load-on-startup&gt;0&lt;/load-on-startup&gt;

  &lt;/servlet&gt;

  &lt;filter&gt;

        &lt;filter-name&gt;Myfilter1&lt;/filter-name&gt;

        &lt;filter-class&gt;com.cakin.filters.Myfilter1&lt;/filter-class&gt;

  &lt;/filter&gt;

  &lt;filter-mapping&gt;

        &lt;filter-name&gt;Myfilter1&lt;/filter-name&gt;

        &lt;url-pattern&gt;/\*&lt;/url-pattern&gt;

  &lt;/filter-mapping&gt;

  &lt;servlet-mapping&gt;

    &lt;servlet-name&gt;action&lt;/servlet-name&gt;

    &lt;url-pattern&gt;\*.do&lt;/url-pattern&gt;

  &lt;/servlet-mapping&gt;

 

  &lt;welcome-file-list&gt;

    &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;

  &lt;/welcome-file-list&gt;

&lt;/web-app&gt;

 

三 测试结果

![](http://dl2.iteye.com/upload/attachment/0127/5595/54d3f745-5eac-3aab-b41d-67811b52b860.png)  
 

 

四 怎样配置多个struts-config文件

在web.xml文件可以配置

    &lt;init-param&gt;

      &lt;param-name&gt;config&lt;/param-name&gt;

      &lt;param-value&gt;/WEB-INF/config/struts-config.xml,/WEB-INF/config/struts-config-2.xml&lt;/param-value&gt;

    &lt;/init-param&gt;

 

    &lt;init-param&gt;