This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSP and the fly likes How to get username of currently logged user on client machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to get username of currently logged user on client machine" Watch "How to get username of currently logged user on client machine" New topic
Author

How to get username of currently logged user on client machine

Shobhit Khandelwal
Greenhorn

Joined: Feb 19, 2009
Posts: 24
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: 39535
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Shobhit Khandelwal
Greenhorn

Joined: Feb 19, 2009
Posts: 24
Yes this is a web app but login is not needed and so is the requirement given to me.
Is there any other way to deal with this?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

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
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: 39535
    
  27
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
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
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
Start here: http://www.coderanch.com/how-to/java/ServletsFaq#security
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get username of currently logged user on client machine
 
Similar Threads
How to prevent multiple logins
windows user name
Computer name through JDBC
Need to get the user id of the machine raising the request.
Java - Getting Login ID