@RequestMapping(value="/test") @ResponseBody public void test1(HttpServletRequest request,Questionnaire quest,String questOptions){ String ipAddress = null; if (request.getHeader("x-forwarded-for") == null) { ipAddress = request.getRemoteAddr(); }else{ if(request.getHeader("x-forwarded-for").length() > 15){ String [] aStr = request.getHeader("x-forwarded-for").split(","); ipAddress = aStr[0]; } else{ ipAddress = request.getHeader("x-forwarded-for"); } } String terminal = request.getHeader("User-Agent"); if(terminal.contains("Windows NT")){ terminal = "PC端"; }else{ terminal = "移动端"; } System.out.println("访客IP:"+ipAddress); System.out.println("用户访问来源:"+terminal); System.out.println("访问URL:"+request.getRequestURL()); }