【问题标题】:Confusion in understanding include file in my web application在我的 Web 应用程序中理解包含文件的困惑
【发布时间】:2011-06-09 07:55:23
【问题描述】:

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

【问题讨论】:

    标签: java jsp web-applications servlets scriptlet


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 2013-10-29
      • 1970-01-01
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多