一、web应用的classpath简介
classpath路径在每个J2ee项目中都会用到,即WEB-INF下面的classes目录,所有src目录下面的java、xml、properties等文件编译后都会在此,所以在开发时常将相应的xml配置文件放于src或其子目录下。
Struts
2框架有两个核心配置文件,其中struts.xml文件主要负责管理应用中的Action映射,以及该Action包含的Result定义等。除此之
外,Struts
2框架还包含
struts.properties文件,该文件定义了Struts
2框架的大量属性,开发者可以通过改变这些属性来满足应用的需求。
二、解决方案
思路:struts.properties文件和struts.xml文件通常放在Web应用的WEB-INF/classes路径下。实际上,只要将该文件放在Web应用的CLASSPATH路径下,Struts 2框架就可以加载该文件。
方法一、将xml或properties文件放入Source Folder文件夹中
右键项目/New/Source Folder 然后在该source Folder中新建struts.properties文件或者struts.xml文件即可!!!(实际上,最终struts.properties文件或者struts.xml文件还是被编译到WEB-INF下面的classes目录)
方法二、添加源文件路径到classPath中
在任意位置新建文件夹(不防文件夹取名properties),如下图:

2、在properties文件夹中新建struts.properties和其他.properties文件,如下图

3、重点:添加给properties文件夹到classPath中
右键项目/Built Path/Configure Built Path/选择Source标签 后在右侧点击Add Folder

在弹出的对话框中选择properties文件夹,ok即可

(实际上:struts.properties文件和其他.properties文件都被编译到WEB-INF目录下的properties文件中了)
二、解决方案
思路:struts.properties文件和struts.xml文件通常放在Web应用的WEB-INF/classes路径下。实际上,只要将该文件放在Web应用的CLASSPATH路径下,Struts 2框架就可以加载该文件。
方法一、将xml或properties文件放入Source Folder文件夹中
右键项目/New/Source Folder 然后在该source Folder中新建struts.properties文件或者struts.xml文件即可!!!(实际上,最终struts.properties文件或者struts.xml文件还是被编译到WEB-INF下面的classes目录)
方法二、添加源文件路径到classPath中
在任意位置新建文件夹(不防文件夹取名properties),如下图:
2、在properties文件夹中新建struts.properties和其他.properties文件,如下图
3、重点:添加给properties文件夹到classPath中
右键项目/Built Path/Configure Built Path/选择Source标签 后在右侧点击Add Folder
在弹出的对话框中选择properties文件夹,ok即可
(实际上:struts.properties文件和其他.properties文件都被编译到WEB-INF目录下的properties文件中了)