i have website hosted on local server and this website is accessed by several local users, and i want when they access specific page to get the os user for the client/user a
String userAgent = request.getHeader("User-Agent");
You can get a full list of all user-agent values from this web site, http://www.user-agents.org/
Javascript Way
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
and send the OSName variable back to the server.
Create jar which consist of applet where applet can get current user name by using System.getProperty("user.name")
write httpclient in same applet where it sends current user name to servlet which is on your server.
call current user method is applet
assign username to httpclient
send user name to servlet using httpclient
Your program give username of server not the client that's why you have to user client side technology like applet which resides in client machine.
using java method request.getRemoteUser()
did the trick.