ข้ามไปที่เนื้อหาหลัก

How to get client IP Address in springboot (Java)


import javax.servlet.http.HttpServletRequest;

//...
@Autowired
public HttpServletRequest request;
public boolean _isLocalhost() {

String[] _host = null;
boolean _localhost;
try {
_host = (request.getHeader("referer")).split("/");
} catch (Exception e) {
// TODO: handle exception
}
if (_host[2].equals("localhost")) {
_localhost = true ;
} else {
_localhost = false;
}
  return  _localhost;
}
เรียกใช้ตามนี้ครับ :  _isLocalhost()==true? ... : ... 

ความคิดเห็น