手机java浏览器 JAVA获取绝对路径的问题如何解决?

JAVA获取绝对路径的问题如何解决?1使用servlet 1.1获取项目的绝对路径请求.getSession(). Getservletcontext()。Getrealpath(”)1.2获取浏览器

JAVA获取绝对路径的问题如何解决?

1使用servlet 1.1获取项目的绝对路径请求.getSession(). Getservletcontext()。Getrealpath(”)1.

2获取浏览器地址request.getRequestURL()1.

3获取当前文件的绝对路径请求.getSession().getServletContext().getRealPath(请求.getRequestURI()) 2. 获取当前classpath字符串A2=类名class.getResource类(“”).toString()字符串a3=DBConnection.class.getResource(“/”).toString()字符串a4=DBConnection.class.getClassLoader().getResource(“”).toString()字符串t=线程.currentThread(). Getcontextclassloader()。获取资源(“”)。Getpath()//可以很好地理解输出。三。获取文件t=线程.currentThread(). Getcontextclassloader()。获取资源(“”)。Getpath()int num=t.indexof(”。Metadata”)字符串路径=t.substring(1,Num)。替换(“/”,“ ”)“项目名称webcontent文件”