Is it possible to get client os user name in java web application?

前端 未结 3 952
迷失自我
迷失自我 2020-12-21 22:41

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

相关标签:
3条回答
  • 2020-12-21 23:22
    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.

    0 讨论(0)
  • 2020-12-21 23:27

    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.

    1. call current user method is applet

    2. assign username to httpclient

    3. 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.

    0 讨论(0)
  • 2020-12-21 23:35

    using java method request.getRemoteUser() did the trick.

    0 讨论(0)
提交回复
热议问题