大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
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\从request获取各种路径总结request.getRealPath("url"); // 虚拟目录映射为实际目录request.getRealPath("./"); // 网页所在的目录request.getRealPath("../"); // 网页所在目录的上一层目录request.getContextPath(); // 应用的web目录的名称如http://localhost:7001/bookStore//bookStore/ => [contextPath] (request.getContextPath())获取Web项目的全路径String strDirPath = request.getSession().getServletContext().getRealPath("/");以工程名为TEST为例:(1)得到包含工程名的当前页面全路径:request.getRequestURI()结果:/TEST/test.jsp(2)得到工程名:request.getContextPath()结果:/TEST(3)得到当前页面所在目录下全名称:request.getServletPath()结果:如果页面在jsp目录下 /TEST/jsp/test.jsp(4)得到页面所在服务器的全路径:application.getRealPath("页面.jsp")结果:D:\resin\webapps\TEST\test.jsp(5)得到页面所在服务器的绝对路径:absPath=new java.io.File(application.getRealPath(request.getRequestURI())).getParent();结果:D:\resin\webapps\TEST2.在类中取得路径:(1)类的绝对路径:Class.class.getClass().getResource("/").getPath()结果:/D:/TEST/WebRoot/WEB-INF/classes/pack/(2)得到工程的路径:System.getProperty("user.dir")结果:D:\TEST3.在Servlet中取得路径:(1)得到工程目录:request.getSession().getServletContext().getRealPath("") 参数可具体到包名。结果:E:\Tomcat\webapps\TEST(2)得到IE地址栏地址:request.getRequestURL()结果:http://localhost:8080/TEST/test(3)得到相对地址:request.getRequestURI()结果:/TEST/test
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/193576.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...