That's quite simple, as it is teh user, which is executing the request; so somehting like
request.getUserPrincipal()
from the Java servlet API should do the trick. But be aware: The clientside code is always executed in the browser; but when all the responses the client browser made to the server, are actually delivered from a cache, your serverside code is never executed. So if you want to cache your pages, you should not rely on your serverside code.
kind regards,
Jörg