当前位置:网站首页>JSP如何使用request获取当前访问者的真实IP呢?
JSP如何使用request获取当前访问者的真实IP呢?
2022-08-02 00:01:00 【qq_25073223】
转自:
下文讲述获取访问者的真实IP的方法分享,如下所示:
当使用反向代理后,我们<%=request.getRemoteAddr() %>,会返回127.0.0.1
那么如何获取访问者的IP信息呢?下文将一一道来,如下所示:
实现思路:
借助以下方法即可获取访问者的真实IP
public String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
边栏推荐
猜你喜欢

TCL:在Quartus中使用tcl脚本语言进行管脚约束

solidity

认识USB、Type-C、闪电、雷电接口

background-image使用
![[Three sons] C language implements simple three sons](/img/96/c3f6c331cbc6d794dc5381cf176ba7.png)
[Three sons] C language implements simple three sons

【MySQL篇】初识数据库

面试必问的HashCode技术内幕

Various Joins of Sql

oozie startup error on cdh's hue, Cannot allocate containers as requested resource is greater than maximum allowed

TCP 可靠吗?为什么?
随机推荐
【加密周报】经济衰退在加息气氛中蔓延 美联储“放手一搏”?盘点上周加密市场发生的重大事件
@WebServlet注解(Servlet注解)
图解LeetCode——1161. 最大层内元素和(难度:中等)
双队列实现栈?双栈实现队列?
【ACWing】230. 排列计数
08-SDRAM:汇总
Win11如何获得最佳电源效率?
DVWA靶场环境搭建
【MySQL系列】 MySQL表的增删改查(进阶)
Axure tutorial - the new base (small white strongly recommended!!!)
cdh6 opens oozieWeb page, Oozie web console is disabled.
Thymeleaf简介
With a monthly salary of 12K, the butterfly changed to a new one and moved forward bravely - she doubled her monthly salary through the career change test~
Unity—四元数、欧拉角API+坐标系统
在不完全恢复、控制文件被创建或还原后,必须使用 RESETLOGS 打开数据库,解释 RESETLOGS.
security CSRF Vulnerability Protection
yay 报错 response decoding failed: invalid character ‘<‘ looking for beginning of value;
在MySQL中使用MD5加密【入门体验】
Bean的生命周期
security 会话并发管理