-
2월 16일 - spring에서 클라이언트 ip 가져오기공부/자잘한 정보 2022. 2. 16. 17:48
@Controller public class HomeController { @RequestMapping(value = "/", method = RequestMethod.GET) public String home(Model model) { HttpServletRequest req = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); String ip = req.getHeader("X-FORWARDED-FOR"); if (ip == null) ip = req.getRemoteAddr(); model.addAttribute("clientIP", ip); return "home"; } }
참고글
https://www.lesstif.com/java/spring-client-ip-18220218.html
'공부 > 자잘한 정보' 카테고리의 다른 글
2월 18일 - sequelize view (0) 2022.02.19 2월 17일 - 307 상태 코드 (0) 2022.02.18 2월 15일 - express에서 url 파라미터 쓰기 (0) 2022.02.15 2월 14일 - 클린코드(2) (0) 2022.02.14 2월 13일 - 클린코드(1) (0) 2022.02.13