从Request对象中可以获取各种路径信息,以下例子:

假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String remoteAddress=request.getRemoteAddr();
String servletPath=request.getServletPath();
String realPath=request.getRealPath("/");
String remoteUser=request.getRemoteUser();
String requestURI=request.getRequestURI();
 
out.println("path:"+path+"<br>");
out.println("basePath:"+basePath+"<br>");
out.println("remoteAddr:"+remoteAddress+"<br>");
out.println("servletPath:"+servletPath+"<br>");
out.println("realPath:"+realPath+"<br>");
out.println("remoteUser:"+remoteUser+"<br>");
out.println("requestURI:"+requestURI+"<br>");
 
结果:
path:/WebDemo
basePath:http://localhost:8683/WebDemo/
remoteAddr:127.0.0.1
servletPath:/index.jsp
realPath:D:\apache-tomcat-6.0.13\webapps\WebDemo\
remoteUser:null
requestURI:/WebDemo/index.jsp
 
从上不难看出request各个对应方法所代表的含义
 
 

获取Request请求的路径信息的更多相关文章

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

    1.jstl标签c:remove删除session request.getSession().setAttribute("ssmsg", "修改成功"); &l ...

  2. django 获取request请求对象及response响应对象中的各种属性值

    django request对象和HttpResponse对象 HttpRequest对象(除非特殊说明,所有属性都是只读,session属性是个例外) HttpRequest.scheme 请求方案 ...

  3. 测开之路一百二十六:flask之获取request请求数据

    可以根据flask的request对象获取所有的请求信息 path = request.path # 获取请求地址method = request.method # 获取请求方法ip = reques ...

  4. springmvc 获取request 和 java路径分隔符 在windows 和linux 下自动判断的方法

    //获取requert HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestA ...

  5. 在Global.asax文件的Application_BeginRequest中获取request请求内容

    protected void Application_BeginRequest(object sender, EventArgs e) { try { string isLogRequest = Sy ...

  6. js获取http请求响应头信息

    var req = new XMLHttpRequest(); req.open('GET', document.location, false); req.send(null); var heade ...

  7. FastAPI(54)- 详解 Request 请求对象

    背景 前面讲了可以自定义 Response,那么这里就讲下请求对象 Request 可以通过 Request 来获取一些数据 获取请求基础信息 @app.get("/base") ...

  8. 动态获取jar文件的路径

    下面专门封装了一个类来处理: import  java.io.File; /** * 获取打包后jar的路径信息 * @author Administrator *  2011-01-16 13:53 ...

  9. ASP.NET获取请求的url信息汇总

    ASP.NET获取请求的url信息汇总 最近做项目需要处理一个用代码获取当前网站的域名或ip信息的问题,于是尝试了ASP.NET中各种获取url信息的方法,在此总结一下: 在Global.asax文件 ...

随机推荐

  1. linux下ping加时间戳实时输出到文件 放后台运行

    放后台运行命令:setsid 实时输出命令:unbuffer 加时间戳:awk '{ print $0"\t" strftime("%D_%H:%M:%S",s ...

  2. ios开发--GCD使用介绍:4-延迟执行操作

    在开发过程中,我们有时会希望把一些操作封装起来延迟一段时间后再执行.iOS开发中,有两种常用的方法可以实现延迟执行,一种是使用GCD,另外一种是使用NSRunLoop类中提供的方法. 1.使用GCD实 ...

  3. 使用 JAX-RS 简化 REST 应用开发

    本文将详细介绍 Java EE 6 中所引入的对 JSR-311 (JAX-RS : Java API for RESTful Web Services) 的支持,并通过一个完整的示例应用程序展示 J ...

  4. 294. Flip Game II

    题目: You are playing the following Flip Game with your friend: Given a string that contains only thes ...

  5. C# 公关类(全)

    http://tool.sufeinet.com/CodePreview/CodeView.aspx?action=view&file=FTP/FTPClient.cs

  6. Iterator的remove方法可保证从源集合中安全地删除对象(转)

    如果对正在被迭代的集合进行结构上的改变(即对该集合使用add.remove或clear方法),那么迭代器就不再合法(并且在其后使用该迭代器将会有ConcurrentModificationExcept ...

  7. Docker基础技术:DeviceMapper

    在上一篇介绍AUFS的文章中,大家可以看到,Docker的分层镜像是怎么通过UnionFS这种文件系统做到的,但是,因为Docker首选的AUFS并不在Linux的内核主干里,所以,对于非Ubuntu ...

  8. asp.net MVC3 “System.Web.Mvc.ModelClientValidationRule”问题

    错误提示: Error 1 The type 'System.Web.Mvc.ModelClientValidationRule' exists in both 'c:\Program Files ( ...

  9. 蓝牙接收苹果手机通知 ANCS协议分析

    蓝牙接收苹果手机通知 ANCS协议分析 转载,请注明出处:http://www.cnblogs.com/alexcai/p/4321514.html 综述 现在有许多蓝牙手表.手环都能接收苹果ipho ...

  10. cmake的使用二:链接第三方静态库

    cmake的使用二:链接第三方静态库