-1

以下のコード スニペットを理解するのに問題があります。実際には .inc ファイルの内容です。私が混乱しているのは、パス変数に格納されるものです。現在作業中のディレクトリのパスか、それ以外のパスか...

<%
      String path = application.getRealPath(request.getServletPath());
      path = path.substring(0, path.lastIndexOf(java.io.File.separator));
      String dictionaryPath = path + java.io.File.separator + "dictionaries/english.txt";
      String userdict = path + java.io.File.separator + "spellchecker/dictionaries/user/user-dictionary.txt";

        int searchdepth = 50;

       boolean striphtml = true;

       String format = "javascript";
       int     suggestions = 14;
    if (request.getParameter("jsvar") != null) {
        if (!java.util.regex.Pattern.matches("^[a-zA-Z0-9_.\\[\\]]+$", request.getParameter("jsvar"))) {
            out.println("Invalid Jsvar");
            return;
        }
    }
%>
4

1 に答える 1

1

ドキュメントを参照してください。context.getRealPath()およびrequest.getServletPath()という他に優れた代替手段はありません。

ところで、それを印刷するのはどうですか、

String path = application.getRealPath(request.getServletPath());
System.out.println("path: " + path);

path = path.substring(0, path.lastIndexOf(java.io.File.separator));
System.out.println("path: " + path);

String dictionaryPath = path + java.io.File.separator + "dictionaries/english.txt";
System.out.println("dictionaryPath: " + dictionaryPath);

String userdict = path + java.io.File.separator + "spellchecker/dictionaries/user/user-dictionary.txt";
System.out.println("userdict: " + userdict);
于 2011-06-09T08:24:59.470 に答える