• 后台访问记录


    前台

    <script type="text/javascript">
    	$(document).ready(function () {
    		$.getJSON("/portal/visitor/updateVisitor?rn="+Math.random(),function(data){
    			if("success"==data.result){
    				//parent.location.href="/portal/home/index";
    			}
    			else{
    				alert("logout failure!");
    			}
    		});			
    	});
    </script>
    

     后台处理

    @RequestMapping("/updateVisitor")
    	public void updateVisitor(HttpServletRequest request,HttpServletResponse response){
    		 boolean flag=false;
    		 System.out.println(request.getRemoteHost());
    		 System.out.println(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
    		 System.out.println(new SimpleDateFormat("yyyy/MM/dd").format(new Date()));
    		 
    		 
    		 
    		 List<Visitor> allVisitors = visitorService.findAll();
    		 for(Visitor vis:allVisitors){
    			 String ip=request.getRemoteHost();
    			 if(request.getRemoteHost().equals(vis.getIp())){
    				 flag=true;
    			 }
    		 }
    		 
    		 if(flag==false){
    			 Visitor visitor = new Visitor();
    			 visitor.setIp(request.getRemoteHost());
    			 visitor.setName("***");
    			 visitor.setVisitTime(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
    			 visitor.setVisitDate(new SimpleDateFormat("yyyy/MM/dd").format(new Date()));
    			 visitorService.save(visitor);
    		 }
    		 else{
    				 visitorService.updateByIP(request.getRemoteHost(),new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()),new SimpleDateFormat("yyyy/MM/dd").format(new Date()));
    		 }
    		 
    		 Long totalToday = visitorService.todayVisitor();
    		 request.getSession().setAttribute("total", totalToday);
    		 JSONObject data = new JSONObject();
    			try {
    				data.put("result", "success");
    			} catch (Exception e) {
    				System.out.println(e.getMessage());
    			}
    			
    			
    			PrintWriter out = null;
    			response.setCharacterEncoding("UTF-8");
    			response.setContentType("text/html; charset=UTF-8"); 
    		    try {
    		    	out=response.getWriter();
    		        out.write(data.toString());
    		        out.flush();
    				out.close();	
    		    } catch (IOException e) {
    		        e.printStackTrace();
    		    }	   
    		 
    	}
    

     todayVisitor函数

    public Long todayVisitor() {
    	SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    	List<Visitor> list = getSession().createQuery("FROM Visitor v WHERE  v.visitDate like'%"+df.format(new Date())+"%'").list();
    	Long count = Long.valueOf(list.size());
    	return count;
    }
    
  • 相关阅读:
    14.[保护模式]TSS任务段
    13.[保护模式]陷阱门
    12.[保护模式]中断门
    11.[保护模式]调用门
    10.[保护模式]长调用与短调用
    9.[保护模式]代码的跨段跳转流程
    8.[保护模式]段权限检查
    7.[保护模式]段描述符DB位
    6.[保护模式]段描述符属性_S位_TYPE域
    5.[保护模式]段描述符属性_P位_G位
  • 原文地址:https://www.cnblogs.com/wujixing/p/5952124.html
Copyright © 2020-2023  润新知