在我的 grails 应用程序中,我实现了接口(interface) HttpSessionListener
以监听 session 创建,如下所示:
class MyHttpSessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent event) {
log.info "***************** Session created: id= ${event.getSession()?.id}"
}
}
现在,我想记录负责创建 session 的 IP 地址。
我该怎么做?
最佳答案
您可以访问 RequestContextHolder 并获取值
String ipAddr = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes())
.getRequest().getRemoteAddr();
关于java - 创建 session 时如何获取IP地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3597083/