2011-06-09 30 views
-1

我在理解下面提到的代碼片段時遇到了問題。實際上,它是.inc文件中的一個內容。我感到困惑的是存儲在路徑變量中的內容。 不會是當前的工作目錄或任何其他的路徑...理解上的困惑在我的web應用程序中包含文件

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

回答

1

參考文檔,沒有其他更好的替代品,context.getRealPath()request.getServletPath()

BTW,如何打印了這一點,

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); 
+0

感謝您的答覆....有點幫助......但還是要做的事情.... :) – 2011-06-09 09:16:40

+0

@Abhimanyu:我等待您的項目完成,然後;) – 2011-06-09 09:21:21

+0

@adeel ...謝謝,,,希望我快速做到.... – 2011-06-09 10:05:34

相關問題