This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
How to get username of currently logged user on client machine
Shobhit Khandelwal
Greenhorn
Joined: Feb 19, 2009
Posts: 24
posted
0
Hi,
In my jsp, I require cuurently looged in username in one of the textbox and for this I am using System.getProperty("user.name") but when I access the application from some other machine(client) then this still shows username of logged In user on server. I want this field to be change according to the client machine userId everytime.
Kindly suggest the possible ways.
Thanks
Shobhit
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35246
7
posted
0
That property will always reflect the user on the server, so it's no use for what you're trying to do.
Is this a web app for which a login is required? If so, you could use ServletRequest.getRemoteUser for this.
Your most likely chance of success would be to have an applet which gets that system property from the client and somehow sends it to the server.
Shobhit Khandelwal
Greenhorn
Joined: Feb 19, 2009
Posts: 24
posted
0
Hi All,
Thanks for your replies. I got the solution of this problem in javascript. For those who don't want login page or credentials to be filled by the client, I am providing my javascript function here :
We can access any win32 class through javascript like this and can get whatever system propeerty we want. I mean if it is accessible through cmd then it can be done through javascript like above code.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35246
7
posted
0
Well, you didn't say that a solution that works only on one particular browser on one particular operating system was acceptable. That's generally not the case with web applications (and actually defeats a large part of their purpose).
Shobhit Khandelwal
Greenhorn
Joined: Feb 19, 2009
Posts: 24
posted
0
Thanks Ulf, I got your point. Yes, I admit that this code is operating system(windows) and browser specific(IE and not sure about other browsers)
Anwarul Yaseen Shahul Hameed
Greenhorn
Joined: Mar 07, 2012
Posts: 1
posted
0
Ulf Dittmer wrote:That property will always reflect the user on the server, so it's no use for what you're trying to do.
Is this a web app for which a login is required? If so, you could use ServletRequest.getRemoteUser for this.
Can you give some example to use ServletRequest.getRemoteUser