user2553198
user2553198

Reputation: 1

Need currently logged in Windows user name in java

An Java application is hosted in Linux server. and we are trying to access the windows username of the user who tries to access the application using browser.

In the jsp, we are trying to print the username of the user with the below lines of code.

<% String user = System.getProperty("user.name");
      out.println(user);
     %>

But the output prints the username of the linux server and not the windows user.

Upvotes: 0

Views: 2003

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 149185

Oups, in a client server application, you must know what runs on server and what runs on client.

The JSP is first translated to java code, compiled and executed server side and produces HTML that is displayed on client. That's the reason why you get the user that runs the server application. You will need an applet (a java application executed client side in a browser) to to that, or you can use javascript as suggested in answers to this question :

@HttpContext.Current.User.Identity.Name

Upvotes: 1

Related Questions