操作系统是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中是不行的
我在项目有一个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中是不行的