Sun and Netscape's web servers have always provided a request-processing "toolkit" of sorts. Over the years, the size of that toolkit has grown. Sun Java System Web Server 7, in particular, adds a number of new tools to the toolkit.
Four of the new tools in Web Server 7 — the
<If> tag, $cookie{...} map variable, uuid() expression function,
and set-cookie SAF — can be used together to track visitors like
the Apache mod_usertrack module does.
For example, you could add the following below the
<Object name="default"> line in the obj.conf configuration
file to give each visitor a unique VISITID
cookie that lasts until they close their web browser:
<If not defined $cookie{'VISITID'}>
ObjectType fn="set-cookie" name="VISITID" value="$(uuid())"
</If>
Since each visitor will now have his or her own cookie, you can identify
individual users in your access logs by including the $cookie{'VISITID'}
variable in the access log format. For example, you might specify the
following in the server.xml configuration file:
<access-log>
<file>../logs/access</file>
<format>"%Req->reqpb.clf-request%" %Req->srvhdrs.clf-status% %Req->srvhdrs.content-length% "$cookie{'VISITID'}"</format>
</access-log>
The toolkit approach to configuration is powerful, but it also means the best way to configure specific functionality isn't always obvious. Please let me know if you ever have an idea for an obscure, exotic, or complicated Sun web server configuration task. I hope I'll be up to the challenge... :)
Trackback URL: http://blogs.sun.com/elving/entry/user_tracking_cookie
Hi,
I tried this, but when I check my access log I see "-" where I expect the cookie information to be. Any ideas? Otherwise, I think it's such a great idea. I'm using WS 7.0 Update 1 btw.
thanks,
Rob
Posted by Rob Terro on August 16, 2007 at 01:12 PM PDT #