HttpServletRequest - 如何获取引用URL? [英] HttpServletRequest - how to obtain the referring URL?

查看:123
本文介绍了HttpServletRequest - 如何获取引用URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Java Servlet中记录链接到我的站点的URL。

I need to log URLs that are linking to my site in a Java Servlet.

推荐答案

它可以在 HTTP referer header 。您可以按如下方式在servlet中获取它:

It's available in the HTTP referer header. You can get it in a servlet as follows:

String referrer = request.getHeader("referer"); // Yes, with the legendary misspelling.

但是,您需要意识到这是一个客户控制的值,因此可以欺骗完全不同甚至删除的东西。因此,无论它返回什么值,您都不应该将它用于后端的任何关键业务流程,而只能用于表示控制(例如隐藏/显示/更改某些纯布局部分)和/或统计数据。

You, however, need to realize that this is a client-controlled value and can thus be spoofed to something entirely different or even removed. Thus, whatever value it returns, you should not use it for any critical business processes in the backend, but only for presentation control (e.g. hiding/showing/changing certain pure layout parts) and/or statistics.

有关错误拼写的背景信息,请参阅维基百科

For the interested, background about the misspelling can be found in Wikipedia.

这篇关于HttpServletRequest - 如何获取引用URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆