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