struts.xml的加载路径及配置问题
2015-03-29 13:27
405 查看
<span style="font-size:14px;">本人在配置在使用struts2整合spring时,把配置文件struts.xml放在WEB-IN下时,出现请求无效,当把struts.xml放在src下时有正常了,
struts.xml一般不是放在WEB-IN下的吗?为什么会出现这种现象?</span>
<span style="font-size:14px;">可是用struts1.x的时候,struts-config.xml也是放在WEB-INF下的啊,struts2跟struts1在这点上不一样吗?
可是我单用struts2没有整合spring时,struts.xml也是放在WEB-INF下也没有问题啊
</span><pre name="code" id="answer-content-464384745" class="answer-text mb-10"><span style="font-size:14px;">这个得从struts2的控制器org.apache.struts2.dispatcher.FilterDispatcher上说,这个类默认的是导入/classes 下的struts.xml,所以你可以修改<span style="color:#000000;"><a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=web.xml&fr=qb_search_exp&ie=utf8" rel="nofollow">web.xml</a>文件
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>config</param-name>
<!-- 配置装载struts.xml路径,其中struts.xml放在/src/struts/下-->
<param-value>struts-default.xml,struts-plugin.xml,../struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这样配置之后,你的struts.xml就可以放在/WEB-INF下了</span></span>
<span style="font-size:14px;">这属于框架规范问题
spring配置文件可以放在多各地方 通过配置文件找到
struts2就只能放到src目录下了</span>
ps:
struts2.x配置文件的默认存放路径是在/WEB-INF/classes目录下,也就是说,把struts.xml放在src的目录下。
但是有时,我们为了方便,希望把它放到其他位置,这里简单介绍一下处理的方法。 首先我们要明白struts2
加载配置文件都是从它自己的jar包和\WEB-INF\classes两个默认的位置加载的。
这里需要注意的是,如果你设置了<param-name>config</param-name>参数,那么struts-default.xml等原来
struts2默认加载的文件你也要指定,否则它好像不会自动加载,会出错。
而struts-plugin.xml,也要放在这里,
是因为什么呢。在struts2使用2.1.6版本时,仔细查看了一下struts2-spring-plugin-2.1.6.jar(如果需要和spring集
成的话)中有struts-plugin.xm这个文件,另外json-plugin-0.34.jar(如果struts2要支持json的话,需要这个jar)
中也有一个叫struts-plugin.xm的文件。因此这个文件也是要加载的。最后,是struts.xml文件,这里必须采用相
对\WEB-INF\classes的相对路径。我这里是放在了\WEB-INF\classes\struts目录下。
如果不在这里配置struts-default.xml,struts-plugin.xml,也可以在struts.xml文件中添加
<include file="struts-plugin.xml"></include>和<include file="struts-plugin.xml"></include>来代替。
我写的都是放在src目录下,jsp都是放在web-inf下面,安全性高,通过action访问! 页面放在web-inf下面的时候,外部是无法直
接访问的,只能通过action跳转才能访问,安全性相对而言比较高
相关文章推荐
- struts.xml的加载路径及配置问题
- struts.xml的加载路径及配置问题
- struts.xml的加载路径及配置问题
- struts.xml的加载路径及配置问题
- 搭建SSH框架遇到的struts.xml找不到spring定义的bean的错误(配置文件的路径问题)
- spring 打入jar包 xml配置路径,加载异常等常见问题解决方法
- 【Struts2文件下载】struts.xml文件中配置action,访问路径问题
- 修改Struts2的struts.xml配置文件位置和名称-重点是init-param参数用来切换加载的路径
- Spring 加载xml配置文件路径问题
- struts.xml如何加载到及配置问题
- 通过struts.xml配置映射后的jsp引入外部css和js的路径问题及css中图片url路径问题
- struts2中改变struts.xml默认路径 或可能遇到的问题
- struts.xml常见配置问题
- struts2-core-2.1.6.jar!/struts-default.xml无法加载的问题
- 路径名称和struts.xml配置不一致导致struts2报404
- web.xml中如何设置配置文件的加载路径
- myeclipse部署maven时,src/main/resources里面配置文件加载不到webapp下classes路径下的问题
- 详解struts.xml配置文件constant常量配置问题
- ibatis的sql-map-config配置文件加载资源文件的路径问题-java web project
- 【开发过程问题汇总系列】【B/S struts2】加好jar包且配置好struts.xml后action还是无法请求的问题