java web项目中java web xml配置文件件找不到

1466人阅读
Java后台(134)
在Java web项目中经常会用属性文件作为配置文件,而其一般放在src的根目录下,读取文件时一般会有以下两种情况:
方式一、在servlet中读取:
public&static&final&String
ACTIONPATH =&&WEB-INF/classes/actions.properties&;&
public&static&final&Properties
prop =&new&Properties();&
path = getServletContext().getRealPath(&\&);&&&&
FileInputStream
fis =&new&FileInputStream(new&File(path
+ ACTIONPATH));&&&&
prop.load(fis);
方式二、在一般的类中读取:
public&static&final&String
ACTIONPATH =&&actions.properties&;&
public&static&final&Properties
prop =&new&Properties();&
path = UriFilter.class.getClassLoader().getResource(&&).toURI().getPath();&&&
FileInputStream
fis =&new&FileInputStream(new&File(path
+ ACTIONPATH));&&&&
prop.load(fis);
读取文件的属性的值:
propertyName =&&aa&;&
propertyValue = prop.getProperty(propertyName );
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:208755次
积分:3623
积分:3623
排名:第9483名
原创:152篇
转载:109篇
评论:17条
(7)(28)(9)(3)(6)(2)(3)(1)(2)(16)(63)(59)(35)(18)(9)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
所想、所得,均录于此
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(10661)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_080067',
blogTitle:'MyEclipse编译后,classes目录下没有类文件,也没有目录和配置文件',
blogAbstract:'问题总结:1.重新导入的项目结构与原来的不同src
包等等都和原来的不同,打开项目主目录,中有个.classpath文件,用记事本打开会发现有一行&classpathentry
kind=\"src\"
path=\"src\"/&,估计它的意思就是说你的源文件位置,看看有没有这一行,没有一定要补上,下面就是一些jar包的导入路径,如:',
blogTag:'path,myeclipse,classes,jar,配置文件',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:0,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:1,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:true,
hostIntro:'所想、所得,均录于此',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}JAVA加载WEB项目启动后修改的配置文件内容_java web项目启动加载_词汇网
<meta name="keywords" content="JAVA加载WEB项目启动后修改的配置文件内容java web项目启动加载,不多说,基本都能看明白
代码片段(1)[全屏查看所有代," />
JAVA加载WEB项目启动后修改的配置文件内容
责任编辑:词汇网 发表时间: 13:14:55
不多说,基本都能看明白 标签:
代码片段(1)[全屏查看所有代码] 1.[代码][Java]代码 /** * 动态获取配置文件值(不重启获取修改后的配置文件值) * 效率有一定影响 * @param propertisFile 配置文件名称( class目录) * @param property 需要获取的配置项的名称 * @return */public static Map loadProperties(String propertisFile,String... property){Map properties =// 获取执行根目录String path = Thread.currentThread().getContextClassLoader().getResource(propertisFile).getPath();Properties props = new Properties();InputStream is =try {is = new FileInputStream(new File(path));properties = new HashMap();// 用文件流的方式加载配置文件props.load(is);// 读取配置文件,配置项for(String pro:property)properties.put(pro, props.getProperty(pro));} catch (IOException e) {// TODO Auto-generated catch block} finally {try {if (null != is)is.close();} catch (IOException e) {// TODO Auto-generated catch block}}}
上一集:没有了 下一集:
相关文章:&&&&&&&&&&&&
最新添加资讯
24小时热门资讯
附近好友搜索}

我要回帖

更多关于 java web xml配置文件 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信