Java路径问题

JSP取路径:

//WEB站点根目录 request.getRealPath("/"); application.getRealPath("/"); //WEB站点JSP编译文件目录 String classFile = getClass().getName().substring(getClass().getName().lastIndexOf(".") + 1)+ ".java"; String path = getClass().getResource(classFileName); //当前请求jsp文件路径 String filepath=request.getRealPath(request.getServletPath()); //得到去掉文件名的路径. String fileseparator=System.getProperty("file.separator"); String webfilepath=""; webfilepath=filepath.substring(0,filepath.lastIndexOf(fileseparator));

 

JAVA取路径:

/** * @author hujing * @version 1.0 * @date 2009-9-9 * @class_displayName FilePath */ public class FilePath { public static FilePath getInstance() { return new FilePath(); } public String getWebClassesPath() { String path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); return path; } /** * get web rootPath */ public static String BL_getRootPath() { //String path = FilePath.getInstance().getWebClassesPath(); String path = FilePath.getInstance().getRootPath(); path = path.substring(6); int t = path.indexOf("WEB-INF"); path = path.substring(0, t); return path; } public String getRootPath() { String path = ""; try { path = Thread.currentThread().getContextClassLoader().getResource("/").toString(); } catch (Exception e) { e.printStackTrace(); } return path; } }

 

你可能感兴趣的:(java,exception,jsp,String,Class,Path)