Tomcat WebApp:在OpenShift上将文件文件存储在上下文根之外时出错

时间:2013-05-24 16:19:36

标签: tomcat web-deployment openshift

我的tomcat Web应用程序上传图像并将其保存在上下文文件夹之外以确保安全性。我在本地机器上测试了代码并且运行正常。

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

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;
}

我不明白问题是什么,因为代码在我的机器上正常工作。托管网站是否允许您在上下文根目录之外保存文件?有没有解决的办法?谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

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

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

相关问题