1

Tomcat Web アプリケーションは、画像をアップロードし、セキュリティのためにコンテキスト フォルダーの外に保存します。ローカル マシンでコードをテストしたところ、完全に動作しました。

OpenShift でコードをホストすると、以下で強調表示されている行で null ポインター例外が発生します。

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

私のマシンではコードが正常に動作するため、何が問題なのかわかりません。ホスティング サイトでは、コンテキスト ルート以外にファイルを保存することはできませんか? これを回避する方法はありますか?ご協力いただきありがとうございます!

4

1 に答える 1