weblogic获取配置文件

操作系统是liunx,应用服务器是weblogic10.2.3.1
我在项目有一个service.txt配置文件,把web程序打成war包放在weblogic服务器中,在访问中却不能找到这个目录?


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String path = request.getServletPath();
System.out.println(path);
//获取配置文件service.txt的全路径
String filePath = this.getServletContext().getRealPath("/service.txt");
System.out.println(filePath);
如果用basePath会抛出异常:
<2010-1-5 下午11时38分49秒 CST> <Error> <HTTP> <BEA-101020> <[ServletContext@10055979[app:_appsdir_mvctemplate_war module:mvctemplate.war path:/mvctemplate spec-version:2.5]] Servlet failed with Exception
java.lang.NullPointerException
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at com.ouruan.mvctemplate.util.ServicesFactory.<init>(ServicesFactory.java:25)
at com.ouruan.mvctemplate.control.ServletAction.doPost(ServletAction.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
Truncated. see log file for complete stacktrace
>
filePath 一直为null
}
这个问题我一直都不有得到解决至到今天终于把问题解决了,在这里我要谢谢“海林“大哥!
将 String filePath = this.getServletContext().getRealPath("/service.txt");改为
InputStream filePath = getServletContext().getResourceAsStream("/service.txt");
问题就解决了!

在tomcat和jboos服务器中String filePath = this.getServletContext().getRealPath("/service.txt");是可以获取到路径,但在weblogic中是不行的
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值