我的网络应用程序中的包含文件理解混乱

发布于 2024-11-15 00:19:26 字数 837 浏览 3 评论 0 原文

我在理解下面提到的代码片段时遇到问题。实际上它是 .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;
        }
    }
%>

I have a problem in understanding the below mentioned code snippet.Actually it a content on .inc file. What i am confused about is what will be stored in the path variable.
will it be the path of the currently working directory or anything else...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小伙你站住 2024-11-22 00:19:26

请参阅文档,没有其他更好的替代品, 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);

Refer to the docs, there is no other better substitute, context.getRealPath() and request.getServletPath().

BTW, how about printing that out,

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文