0

Given a controller action test() as defined below. I can access the request and get the IP as well as the user agent. I want to count the number of requests that access test(). This is easy, I would just increase a counter on every request.

My question is how can I count the unique requests? I.e., I want to count a request coming from the same computer only once. Is there another way than storing all the ip addresses and user agents to see if they already occurred?

def test() {
  println "ip: "+request.getRemoteAddr()
  println "user agent: "+request.getHeader("User-Agent")

}
4

1 回答 1

1

您可以创建一个新的域类:

class RequestCount {
   String ip
   String userAgent
}

然后在每个请求上保存一个新对象。计算唯一条目的数量,您就完成了。

于 2013-07-25T16:08:31.857 回答