tomcat与weblogic服务器中读取properties的方式

最简单的方式(项目中使用):

Properties property = new Properties();

property.load( getServletConfig().getServletContext().getResourceAsStream("/WEB-INF/info.properties"));

String USERNAME = property.getProperty("username");

info.properties文件所存放的位置如图:


——————————————————————————

原来第二行代码是:property.load(getServletContext().getResourceAsStream("/WEB-INF/info.properties"));

在 tomcat 下部署的应用没什么问题,今天部署到 weblogic 下,程序跑不起来了,报错信息如下:

    the method getServletContext() is undefined

ps:我在jsp页面中调用了this.getServletContext() 方法,在 tomcat 下没问题,但部署在 weblogic 下就报错了。

在 google 搜索框中直接输入:weblogic the method getServletContext() is undefined 然后 google ,查出来的第一条是 stackoverflow 上的一个解决方案:

链接地址:http://stackoverflow.com/questions/2964250/jsp-getservletcontext-error

由于 weblogic 下不能这样获取,可以通过 getServletConfig().getServletContext() 这样来获取 servletContext 。从发现到解决这个问题,前后花了不到十分钟的时间。如果用中文搜索,估计半小时也找不到解决方案,刚才用中文关键字在谷歌下搜索了,看了第一页的结果,貌似不是我要搜索的问题。建议大家搞开发的好好学习下英文,用英文搜索能节省很多时间。 


猜你喜欢

转载自blog.csdn.net/u012768459/article/details/80608495
今日推荐