gpt4 book ai didi

Tomcat 网络应用程序 : Error storing image file outside of context root on OpenShift

转载 作者:行者123 更新时间:2023-11-28 22:21:25 24 4
gpt4 key购买 nike

为了安全起见,我的 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;
}

我不明白问题出在哪里,因为代码在我的机器上运行良好。托管站点是否不允许您将文件保存在上下文根之外?有没有解决的办法?感谢您的帮助!

最佳答案

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

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

关于Tomcat 网络应用程序 : Error storing image file outside of context root on OpenShift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16739471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com