现在的位置: 首页 > 综合 > 正文

获取客户端IP地址

2013年03月06日 ⁄ 综合 ⁄ 共 412字 ⁄ 字号 评论关闭

jsp 获取客户端的IP地址 - 云代码

 

 

<%@ page language="java" contentType="text/html; charset=GB2312" pageEncoding="GB2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>获取客户端的IP地址</title>
	</head>

	<body>
		<%
			String realIP = request.getHeader("x-forwarded-for");
			if (realIP != null && realIP.length() != 0) {
				out.print("你的IP地址是:" + realIP);
			} else {
				String ip = request.getRemoteAddr();
				out.print("你的IP地址是:" + ip);
			}
		%>
		<br>
	</body>
</html>

抱歉!评论已关闭.