国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

java之訪問日志

2019-11-14 11:15:46
字體:
供稿:網(wǎng)友

需求:

別人訪問你的網(wǎng)站,你想知道誰訪問你,在哪里訪問的,最好的辦法是站長之家,可是你想自己寫,于是就寫個小小的例子,以供學(xué)習(xí)!

分析:

先從后端獲取ip,然后前端ip通過騰訊地圖獲取省市地址,然后再通過后端保存端口、瀏覽器信息等資料。

主頁面:

<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.5.1/jquery.min.js"></script> <script charset="utf-8" src="http://map.QQ.com/api/js?v=2.exp"></script> <script type="text/Javascript" src="static/visit.net-1.0.js"></script>

visit.net-1.0.js:

window.onload = function(){ $.Ajax( { type : "POST", url : "/sshTest/index/getVisitIp.do", timeout : 20000, cache : false, success : function(data, textStatus) { var ipaddre = data; var geocoder,citylocation,map,marker,locationLat,addresses,PRovince,city,address,ipaddress,ipaddre2 = null; function insertQR(province,city,addresses,locationLat,ipaddre2){ var llac = "'"+locationLat+"'"; alert(llac) $.ajax( { type : "POST", url : "/sshTest/index/visitNet5.do", data : {"province":province, "city":city, "addresses":addresses, "lolat":llac, "ip":ipaddre2 }, cache : false, success : function(data, textStatus) {} }); } var center = new qq.maps.LatLng(39.916527,116.397128); map = new qq.maps.Map(document.getElementById('container'),{ center: center, zoom: 13 }); geocoder = new qq.maps.Geocoder(); citylocation = new qq.maps.CityService({ map : map, complete : function(results){ codeLatLng(results.detail.latLng); } }); function codeLatLng(latLng) { var info = new qq.maps.InfoWindow({map: map}); geocoder.getAddress(latLng); geocoder.setComplete(function(result) { map.setCenter(result.detail.location); locationLat = result.detail.location; addresses = result.detail.address; province=result.detail.addressComponents.province; city=result.detail.addressComponents.city; ipaddre2 = ipaddre; insertQR(province,city,addresses,locationLat,ipaddre2); }); geocoder.setError(function() {}); } var ipaddress = data; citylocation.searchCityByIP(ipaddress); } }); }

controller

@RequestMapping("getVisitIp") @ResponseBody public String getVisitIp(HttpServletRequest request) {// String ip = _ipUtil.getRemoteHost(request); String ip = "14.147.40.76"; return ip; } /** * 訪問日志 * @param province 省 * @param city 市 * @param addresses 詳細(xì)地址 * @param locationLat 經(jīng)緯度 * @param ip ip地址 * @param request * @return */ @RequestMapping("visitNet5") @ResponseBody public void visitNet5(String lolat,Visitnet net,HttpServletRequest request) { net.setLocationlat(lolat.replaceAll("'", "")); int port = request.getRemotePort(); // TCP/IP端口 String agent = request.getHeader("user-agent"); //瀏覽器信息 Date date = new Date(); //訪問時間 net.setPort(port+""); net.setAgent(agent); net.setCreatetime(date); System.out.println(port+agent); }

ipUtil

public static String getRemoteHost(javax.servlet.http.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.equals("0:0:0:0:0:0:0:1")?"127.0.0.1":ip; }

數(shù)據(jù)庫

CREATE TABLE `visitnet` ( `id` int(11) NOT NULL auto_increment, `province` varchar(255) default NULL, `city` varchar(255) default NULL, `addresses` varchar(255) default '' COMMENT '詳細(xì)地址', `locationLat` varchar(255) default '' COMMENT '經(jīng)緯度', `ip` varchar(255) default '' COMMENT 'ip地址', `port` varchar(255) default NULL, `agent` varchar(255) default NULL, `createTime` datetime default NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;

截圖留戀

這里寫圖片描述

全CSDN的豐(好)色(se)博客,這里有書本看不到的Java技術(shù),電影院禁播的電影,歡迎關(guān)注QQ群494808400


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 肥乡县| 承德县| 富阳市| 周口市| 墨竹工卡县| 松原市| 高密市| 江陵县| 綦江县| 阿勒泰市| 松阳县| 潮州市| 建德市| 娱乐| 绥江县| 盐亭县| 普宁市| 朔州市| 凤山市| 西畴县| 新巴尔虎左旗| 白银市| 云南省| 江阴市| 陇西县| 广德县| 古浪县| 静乐县| 张家港市| 盐津县| 卢氏县| 保靖县| 资中县| 旌德县| 台湾省| 德令哈市| 天水市| 始兴县| 吐鲁番市| 肥西县| 三明市|