我的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;
}我不明白是什么问题,因为代码在我的机器上运行得很好。托管网站不允许您在上下文根目录之外保存文件吗?有什么办法可以解决这个问题吗?谢谢你的帮忙!
发布于 2013-05-26 10:45:12
在OpenShift上,您实际拥有写入权限的唯一位置是~/app-root/data和/tmp。
App-root/data有一个您应该在代码$OPENSHIFT_DATA_DIR中使用的环境变量。请更改您的代码以写入此目录。
https://stackoverflow.com/questions/16739471
复制相似问题