AndrewXu

仅为资源搬运,个人还未充分理解...

request.getRealPath不推荐使用request.getRealPath("") 这个方法已经不推荐使用了

 

request.getRealPath不推荐使用request.getRealPath("") 这个方法已经不推荐使用了,那代替它的是什么方法 Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(java.lang.String) instead. request.getSession().getServletContext().getRealPath() 得到站点的绝对地址

 

如request.getSession().getServletContext().getRealPath(File.separator) 得到项目的绝对路径如:

 

D:\ProgramFiles\apache-tomcat-6.0.33\webapps\wt4\

 

request.getSession().getServletContext().getRealPath(“/updload/video/”) 得到项目的绝对路径

 

D:\ProgramFiles\apache-tomcat-6.0.33\webapps\wt4\updload\video\

 


 

获取class文件路径

servletcontext.getRealPath() 方法已经不建议使用了

原则:基本上就是尽量使用j2ee规范中的各层次classloader来获取资源,而不是试图去找文件的绝对路
方法:调用this.getClass().getClassLoader().getResource("/").getPath(); 获取到classes目录的全路径

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2021-05-17
猜你喜欢
  • 2021-12-19
  • 2021-12-09
  • 2021-11-30
  • 2021-12-09
  • 2021-12-19
相关资源
相似解决方案