-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 回答