struts2中改变struts.xml默认路径
struts2.X配置文件默认存放路径在/WEB-INF/classes目录下,即将struts.xml放在src的目录下。
但是为了方便管理,开发人员把struts.xml放到其他位置,处理方法如下。
首先要明白struts2加载配置文件都是从自己的jar包和/WEB-INF/classes两个默认的位置加载的。
若修改struts2.x配置文件的存放位置,在web.xml配置过虑器时,具体配置如下:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,struts/struts.xml</param-value>
</init-param>
</filter>
注意点1
若设置了<param-name>config</param-name>参数,那struts-default.xml等原来struts2默认加载的文件也要手动指定,否则不会自动加载。
注意点2
struts-plugin.xml也需要指定。因为在struts2使用2.1.6版本时:
若需要和spring集成的话,struts2-spring-plugin-2.1.6.jar中有struts-plugin.xml这个文件。
若struts2要支持json的话, json-plugin-0.34.jar中也有一个叫struts-plugin.xm的文件。
因此这个文件也是要加载的。
注意点3
采用相对/WEB-INF/classes的相对路径。本例放在了/WEB-INF/classes/struts目录下。当然也可以写成classpath:struts/struts.xml
注意点4
若不在这里配置struts-default.xml,struts-plugin.xml,也可以在struts.xml文件中添加include标签将两个文件包括进去。
<include file="struts-default.xml" />和<include file="struts-plugin.xml" />
注意点5
使用<include file="..." />标签添加其他子配置文件时,file属性也要是一个相对/WEB-INF/classes的路径。
若子配置文件路径是/WEB-INF/classes/configs/struts/student/struts-config.xml的话,
file属性值应该写configs/struts/student/struts-config.xml。
若有多个子配置文件可以采用扫描的方式<include file="configs/struts/*/*.xml" />
可能遇到的问题:
警告: Could not find action or result
There is no Action mapped for namespace / and action name hello. - [unknown location]
为什么指定了自己的struts.xml文件路径依然访问不到呢?
原因依然在struts加载配置文件的方式,struts并不是获取的配置文件相对应用(项目)的路径,而是相对src,对于web是相对/WEB-INF/classes文件夹的路径,现在知道了最终的解决方案了?
对了,就是把web.xml中的[/WEB-INF/struts.xml]改成 [../struts.xml],即使用相对/WEB-INF/classes文件夹的路径!
struts2中改变struts.xml默认路径的更多相关文章
- Struts2更改配置文件struts.xml默认路径
struts2配置文件默认存放路径在/WEB-INF/classes目录下,即将struts.xml放在src的目录下. 但是为了协作开发与方便管理,我们有时需要把struts.xml放到其他位置 s ...
- 三、改变struts.xml默认路径后web.xml如何配置
http://yanln.iteye.com/blog/2189816(文章很好)
- 转载 Struts2的配置 struts.xml Action详解
在学习struts的时候,我们一定要掌握struts2的工作原理.只有当我们明确了在struts2框架的内部架构的实现过程,在配置整个struts 的框架时,可以很好的进行逻辑上的配置.接下来我就先简 ...
- struts2学习笔记--struts.xml配置文件详解
这一节主要讲解struts2里面的struts.xml的常用标签及作用: 解决乱码问题 <constant name="struts.i18n.encoding" value ...
- [转]在MyEclipse中设置struts.xml自动提示功能
导入标签:<%@ taglib uri="/struts-tags" prefix="s" %> 要想在MyEclipse中实现struts.xml ...
- Ubuntu 中改变文件的默认打开方式(转)
源自:Ubuntu 中改变文件的默认打开方式 1. 相关配置文件 全局配置 /etc/gnome/defaults.list /usr/share/applications/mimeinfo.cac ...
- struts2设置加载非默认路径的struts.xml文件解决方案
方案一: 首先我们要明白struts2加载配置文件都是从它自己的jar包和\WEB-INF\classes两个默认的位置加载的,如果你想改变strusts2中的文件的默认加载路径,可以在web项目 ...
- struts2中struts.xml 放置路径的问题
在搭建struts2项目时如果在web.xml中不指定struts.xml文件的路径,struts2会默认到/WEB-INF/classes中寻找加载其配置文件的,但我就是想把struts的配置文件放 ...
- Struts2中有关struts-default.xml,struts.xml,struts.properties文件详解
1) struts-default.xml 这个文件是struts2框架默认加载的配置文件.它定义struts2一些核心的bean和拦截器. <?xml version="1.0&qu ...
随机推荐
- Useful related java API for Android
Language_suport and Other Language-Oriented API: strings,exceptions, threads, #java.lang.* offers th ...
- Codeforces Round #343 (Div. 2) C. Famil Door and Brackets
题目链接: http://codeforces.com/contest/629/problem/C 题意: 长度为n的括号,已经知道的部分的长度为m,现在其前面和后面补充‘(',或')',使得其长度为 ...
- 20160729noip模拟赛zld
首先显然有多少个奇数,就有多少个回文串是最优的(没有奇数时构造一个回文串 然后有了k个“核心”,把剩下的字符顺序安排到这些的两侧,最后最短的回文串长度就是答案 #include<map> ...
- C#常用简单线程实例
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- 如果使用得当,MySQL 也可以化身 NoSQL
[编者按]随着互联网和移动互联网的发展,各个机构都需要支撑远超过以往的数据.而在这个需求的刺激下,IT 领域出现了大量数据处理技术,其中之一就是 NoSQL .灵活的数据类型,高效的处理能力,让 No ...
- git安装及使用
一.安装 1.从http://code.google.com/p/msysgit/下载Git-1.8.4-preview20130916.exe,并安装. 2.新建git目录,右键选择Git Bash ...
- Oracle index hint syntax
Question: I added an index hint in my query, but the hint is being ignored. What is the correct sy ...
- POJ 1915
#include<iostream> #include<stdio.h> #define MAXN 350 #include"queue" using na ...
- mac上eclipse上配置hadoop
在mac上安装了eclipse之后,配置hadoop其实跟在linux上配置差不多,只是mac上得eclipse和界面和linux上得有点不同. 一:安装eclipse eclipse得安装比较简单, ...
- NET权限系统开源项目
http://www.cnblogs.com/yubaolee/p/OpenAuth.html http://www.cnblogs.com/guozili/p/3496265.html Sereni ...