java 怎样得到用户输入的IP地址或网址
发布网友
发布时间:2022-04-27 09:28
我来回答
共2个回答
热心网友
时间:2023-09-19 13:24
request.getRemoteAddr() 试试
下面转
public String getRemortIP(HttpServletRequest request) {
if (request.getHeader("x-forwarded-for") == null) {
return request.getRemoteAddr();
}
return request.getHeader("x-forwarded-for");
}
获得客户端真实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;
}
热心网友
时间:2023-09-19 13:25
服务器上放段代码,把服务器机器的IP打印到页面就可以了,如果不想让用户看到,就用HTML注释掉或写成<input type="hidden" value="serverIP"/>