Request获取请求之前的URL地址

request.getRequestURL()、**request.getRequestURI()**均不行,获取的是请求的地址。

使用**request.getHeader("Referer")**就可以正确的获取到之前请求的页面URL地址。

Http协议中定义了头部的属性,其中有一个参数"Referer"记录请求之前的页面地址。

In the most common situation this means that when a user clicks a link in a web browser, the browser sends a request to the server holding the destination webpage. The request includes the referrer field, which says the last page the user was on (the one where he/she clicked the link).

浏览器会将请求之前的页面地址记录并发到请求头去,请求中包含了referrer这个属性。

Referrer logging is used to allow websites and web servers to identify where people are visiting them from, for promotional or security purposes. Referrer is a popular tool to combat cross-site request forgery, but such security mechanisms are weakened by the ease of disabling or forging a referrer. The referrer is widely used for statistical purposes.

referrer有效的阻止了跨站攻击(XSS)。

If a website is accessed from a HTTP Secure (HTTPS) connection and a link points to anywhere except another secure location, then the referrer field is not sent. The upcoming standard HTML5 will support the attribute/value rel = "noreferrer" in order to instruct the user agent not to send a referrer.

Https暂不支持referrer,HTML5将会有更多的支持。
参考: http://en.wikipedia.org/wiki/HTTP_referrer

点赞
收藏

评论区

加载中...

相关推荐

《前端实战总结》如何在不刷新页面的情况下改变URL

由于公司最近有个需求是想让我们的get请求的参数都直接显示在浏览器url上,这样我们就可以直接通过复制url来显示对应的界面数据了。背景介绍由于我们常用的http请求一般是基于XHR对象的实现或者fetch实现,这种请求操作并不会触发浏览器url的变化,这样虽然也能正常请求数据并渲染到页面,但是如果用户在当前页面操作了某个get请求并得到了某条数据,想

java代码021

code021.jsp使用request获取客户端信息客户提交的方式:使用的协议:发出请求的客户端地址:发出请求的客户端地址:客户端ip地址:服务器端口:服务器名称:客户端的主机名:客户端请求脚本的文件路径:http协议头信息host的值:http协议头信息useragent的值:http协议头信息acceptlanguage的值:请求文件的绝对路径:

java代码012

code012.jspInserttitlehere<%JSP内置对象1.request用于处理HTTP请求中的各项参数。如,删除可以通过request对象的getParameter()方法获取如,request.getParameter("id")在请求转发时,需要把一些数据传递到转发后的页面处理。就需要用到request的se

Ajax各个参数的说明

Ajax各个参数的说明$.ajax({     url: "http://www.hzhuti.com",    //请求的url地址     dataType: "json",   //返回格式为json     async: true, //请求是否异步,默认为异步,这也是ajax重要特性   

HttpURLConnection(http 1.1) 用法、状态码、状态描述

最近研究了java的HttpURLConnection的用法,这里简单的做一下记录:Java中可以使用HttpURLConnection来请求WEB资源。1、 URL请求的类别分为二类,GET与POST请求。二者的区别在于:     a:)get请求可以获取静态页面,也可以把参数放在URL字串后面,传递给servlet,

3. Vue

路由是根据不同的url地址展现不同的内容或页面。前端路由就是把不同路由对应不同的内容或页面的任务交给前端来做(在单页面应用,大部分页面结构不变,只改变部分内容的使用),之前是通过服务器根据url的不同返回不同的页面。前端路由优点:用户体验好,不需要每次都从服务器全部获取,快速展现给用户缺点:不利于SEO,使用浏