通过HttpServletRequest的request获取各种路径

System.out.println("getContextPath:"+req.getContextPath());
System.out.println("getServletPath:"+req.getServletPath());
System.out.println("getRequestURI:"+req.getRequestURI());
System.out.println("getRequestURL:"+req.getRequestURL());
System.out.println("getRealPath:"+req.getSession().getServletContext().getRealPath("image") );

输出结果为

getContextPath:/maven
getServletPath:/upload.do
getRequestURI:/maven/upload.do
getRequestURL:http://localhost:8080/maven/upload.do
getRealPath:D:\myecllipse\apache-tomcat-7.0.77-windows-x64\apache-tomcat-7.0.77\wtpwebapps\hcwproject\image

最后一个路径其实是工程在那个目录运行路径,不该路径默认会在工作空间

时间: 2024-08-09 02:09:32

通过HttpServletRequest的request获取各种路径的相关文章

request获取各种路径(转)

equest.getRealPath() 这个方法已经不推荐使用了,代替方法是: request.getSession().getServletContext().getRealPath() 在servlet里用this.getServletContect().getRealPath() 在struts里用this.getServlet().getServletContext().getRealPath() 在Action里用ServletActionContext.getRequest().g

从request获取各种路径总结 request.getRealPath("url")

转载:http://blog.csdn.net/piaoxuan1987/article/details/8541839 equest.getRealPath() 这个方法已经不推荐使用了,代替方法是: request.getSession().getServletContext().getRealPath() 从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 S

request 获取各种路径

从request获取各种路径总结 request.getRealPath("url"); // 虚拟目录映射为实际目录 request.getRealPath("./");    // 网页所在的目录 request.getRealPath("../"); // 网页所在目录的上一层目录 request.getContextPath();    // 应用的web目录的名称 如http://localhost:7001/bookStore/ /b

request获取各种路径

转自:http://zjutsoft.iteye.com/blog/1084260 从request获取各种路径总结 request.getRealPath("url"); // 虚拟目录映射为实际目录 request.getRealPath("./");    // 网页所在的目录 request.getRealPath("../"); // 网页所在目录的上一层目录 request.getContextPath();    // 应用的web

Request获取请求路径方法介绍

Request对象通过以下方法来获取请求路径. (1)String getServerName():获取服务器名:localhost (2)String getServerPort():获取服务器端口号:8080 (3)String getContextPath():获取项目名:Test (4)String getServletPath():获取Servlet路径:/login (5)String getQueryString():获取参数部门,即问号后面的部分:username=zhangsa

java request获取相关路径

Request URL: http://localhost:8080/sanjuSCM/scmTruck/list.do?truckno=%E6%B2%AAF00000&companyid_Display=&companyid= String u = request.getRequestURI();   /sanjuSCM/scmTruck/list.do String u2 = request.getContextPath(); /sanjuSCM String u3 = request

jsp Request获取url信息的各种方法比较

从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+&q

jstl删除session,choose,动态获取request当前工程路径

1.jstl标签c:remove删除session request.getSession().setAttribute("ssmsg", "修改成功"); <c:remove var="ssmsg" scope="session" /> 2.jstl标签choose说明 <c:choose> <c:when test="${c.activityType==0}"> <

Android拍照获取照片路径并上传至服务器+Servlet代码

先来客户端代码[这里只写了主要代码] 先来张效果图, iv_photo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new ActionSheetDialog(SendGoodsDetailsActivity.this).builder().setTitle("上传车辆照片") .setCancelable(false).setCanceledOnTouchOuts