jsp java 获取IP 地址的方法
package com.zbb.controller; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/gi") public class GetIpController { @RequestMapping(value = "/gi") public String getRemortIP(HttpServletRequest request) { String idAddr=""; String header = request.getHeader("x-forwarded-for"); if ( header== null) { System.out.println("1"); idAddr= request.getRemoteAddr(); }else{ System.out.println("2"); idAddr=header; } System.out.println(idAddr); return "ui/index"; } }