当前位置:网站首页>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;
}
边栏推荐
- 【MySQL系列】 MySQL表的增删改查(进阶)
- @Scheduled注解详解
- oozie startup error on cdh's hue, Cannot allocate containers as requested resource is greater than maximum allowed
- The Spark of Sql join on the and and where
- 当奈飞的NFT忘记了Web2的业务安全
- security cross-domain configuration
- 【三子棋】C语言实现简易三子棋
- 一篇永久摆脱Mysql时区错误问题,idea数据库可视化插件配置
- TCL:在Quartus中使用tcl脚本语言进行管脚约束
- 使用 Zadig 交付云原生微服务应用
猜你喜欢

How to reinstall Win11?One-click method to reinstall Win11

security CSRF Vulnerability Protection

Use Jenkins for continuous integration, this knowledge point must be mastered

mysql8安装make报错如何解决

玩转NFT夏季:这份工具宝典值得收藏

短视频SEO优化教程 自媒体SEO优化技巧方法

在MySQL中使用MD5加密【入门体验】

【解决】win10下emqx启动报错Unable to load emulator DLL、node.db_role = EMQX_NODE__DB_ROLE = core

【MySQL系列】 MySQL表的增删改查(进阶)

2022还想上岸学习软件测试必看,测试老鸟的肺腑之言...
随机推荐
Artifact XXXwar exploded Artifact is being deployed, please wait...(已解决)
solidity
Axure教程-新手入门基础(小白强烈推荐!!!)
GetHashCode与Equals
NFT工具合集
工件SSMwar exploded 部署工件时出错。请参阅服务器日志了解详细信息
Win10安装DBeaver连接MySQL8、导入和导出数据库详细教程
以交易为生是一种什么体验?
【Leetcode】479. Largest Palindrome Product
yay 报错 response decoding failed: invalid character ‘<‘ looking for beginning of value;
【Leetcode】470. Implement Rand10() Using Rand7()
不就是个TCC分布式事务,有那么难吗?
Thymeleaf简介
【Leetcode】475. Heaters
接地气讲解TCP协议和网络程序设计
C language Qixi is coming!It's time to show the romance of programmers!
【MySQL篇】初识数据库
[Three sons] C language implements simple three sons
QML package management
【解决】win10下emqx启动报错Unable to load emulator DLL、node.db_role = EMQX_NODE__DB_ROLE = core