首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tomcat WebApp:在Tomcat上将图像文件存储在上下文根目录之外时出错

Tomcat WebApp:在Tomcat上将图像文件存储在上下文根目录之外时出错
EN

Stack Overflow用户
提问于 2013-05-25 00:19:36
回答 1查看 612关注 0票数 1

我的tomcat web应用程序上传图像并将其保存在上下文文件夹之外,以确保安全。我在我的本地机器上测试了代码,它工作得很好。

当我在OpenShift上托管代码时,我在下面突出显示的行上得到一个空指针异常:

代码语言:javascript
复制
public void init() throws ServletException {
    // get name of images directory
    String imagesPath = getServletContext().getInitParameter(
            PARAM_UPLOAD_IMAGE_PATH);

    //get path to context root directory
    String contextRoot = getServletContext().getRealPath("/");



    //remove trailing '/'
    contextRoot = contextRoot.substring(0,contextRoot.length() - 1);//NULL POINTER EXCEPTON

    //get path of directory outside root, where images will be saved.
    String outsideRoot = contextRoot.substring(0, contextRoot.lastIndexOf("/"));

    uploadPath = outsideRoot + File.separator + imagesPath;
}

我不明白是什么问题,因为代码在我的机器上运行得很好。托管网站不允许您在上下文根目录之外保存文件吗?有什么办法可以解决这个问题吗?谢谢你的帮忙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-26 10:45:12

在OpenShift上,您实际拥有写入权限的唯一位置是~/app-root/data和/tmp。

App-root/data有一个您应该在代码$OPENSHIFT_DATA_DIR中使用的环境变量。请更改您的代码以写入此目录。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16739471

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档