`

追了getServletContext().getRealPath("/");返回null的问题

阅读更多

今天把程序部署到服务器,发现异常,FileNotFound异常,很快定位到getServletContext().getRealPath("/");返回空的问题。这个问题通常是传递的虚拟路径不对或者使用war包导致的。而我的程序传递的路径肯定正确,并且部署的时候对.war包做了解压。对这个问题上网搜搜了n编,始终找不到问题所在,而部署子本机是完全正确的。

仔细梳理了一下找到了一个线索:我部署到服务器的时候,我等了半天,服务器没帮我把war解压,于是自己把war解压了,而解压之后没有把war包删掉,是不是服务器启动的程序是war包里面的,而不是我解压之后的呢?于是我就rm掉war包,然后开始测试,结果结果同样如此,感觉比较失望,失望之时想起了服务器可能有编译缓存,于是重启服务器,问题终于解决。

 

解决问题的还是要细心梳理清楚,然后定位到问题所在,最后得到解决办法。

 

0
0
分享到:
评论
2 楼 fuliang 2009-12-24  
stevensinclair 写道
用的什么容器?
war包放着按理也不应该有问题。
一般容器都会检测被解压的工程

我也是这么想的,默认会自动解压,但服务器上部署的tomcat不知道怎么配置的,导致了这个问题。
1 楼 stevensinclair 2009-12-24  
用的什么容器?
war包放着按理也不应该有问题。
一般容器都会检测被解压的工程

相关推荐

    多附件上传与下载

    au.setSaveDir(this.servlet.getServletContext().getRealPath("/loadImage/"));//将图片放入存储文件路径 fileName=au.randomFileName(file.getFileName()); au.upload(au.getSaveDir()+File.separator+ ...

    fileupload

    String uploadDirectory = this.getServletContext().getInitParameter("UploadDirectory"); if(!uploadDirectory.contains(":")) { String rootpath = request.getRealPath(request.getRequestURI()); ...

    fileutil工具类 处理文件流工具

    fileutil工具类 处理文件流工具 private static File file; /** * 判断文件是否存在 * * @param path * 文件路径 ...request.getServletContext().getRealPath(path)); return file.exists(); }

    RSA+bcpkix-jdk15.zip

    //返回加密后的字符串 return encryptedString(key, encodeURIComponent(paramStr)); }) 复制代码其中的加密系数可以自定义,这里为:8246a46f44fc4d961e139fd70f4787d272d374532f4d2d9b7cbaad6a15a8c1301319aa...

    JSF文件下载实现

    response,getServletContext().getRealPath(filename),filename); } catch(final IOException e) { System.out.println ( "出现IOException." + e ); } catch(final IllegalStateException e) { System.out....

    strust文件上传

    // 获得系统的绝对路径 String dir = servlet.getServletContext().getRealPath("/image"); //我上传的文件没有放在服务器上。而是存在D:D:\\loadfile\\temp\\ String dir="D:\\loadfile\\temp\\"; int i = 0; ...

    SpringMVC批量上传

    String path = request.getServletContext().getRealPath("/images/")+mkdir; //System.out.println("path="+path); File filepath = new File(path,filename); if(!filepath.getParentFile(&#...

    iReport4.5打印实例

    JasperPrint jasperPrint = JasperFillManager.fillReport(reportFile.getPath(),null,dataSource);//执行报表程序 程序中都很明了 大家肯定会问print.jsp怎么会调用到AppletServlet.java中去执行呢 其实很简单主要...

    jsp探针 ver0.1

    if (freeSpace == null || freeSpace.length() == 0) { return -1; } process.destroy(); freeSpace = freeSpace.trim().replaceAll("\\\\", "\\/"); String[] results = freeSpace.split(" "); for (int i = ...

    servlet2.4doc

    Returns the object bound with the specified name in this session, or null if no object is bound under the name. getAttributeNames() - Method in interface javax.servlet.ServletContext Returns an ...

    jsp内置对象的用法

    13 public Object findAttribute(String name) 寻找一属性,返回起属性值或NULL 14 void removeAttribute(String name) 删除某属性 15 void removeAttribute(String name,int scope) 在指定范围删除某属性 16 ...

Global site tag (gtag.js) - Google Analytics