• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get remote login user name?

 
Amit Chandigarihan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%--This will give my name as I am logged in user of my machine --%>

<% String name;
name = System.getProperty("user.name");
%>User Name of local machine is : <%=name %>
<br>
<%
String rName= request.getRemoteAddr();
java.net.InetAddress localMachine=java.net.InetAddress.getByName(rName);
String username= localMachine.getHostName();
%>Your IP address is: <%=username %>
<br>
The point where I am getting Null:
<%
String str=request.getRemoteUser();
%>


<input type="text" value="<%=str %>">
</body>
</html>


Why request.getRemoteUser( ) gives null. I am on company's network domain. So I want anyone who tries to access my page should get welcome message like Welcome Username of that person on company network.

Is there any other way of doing the same thing?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP runs at the server machine, not the client machine. It will obviously return the details of the server machine, not the client machine.

You need to run code at the client machine and send it to the server machine. You can use a Java applet or Java webstart application for this, or maybe Javascript, but that's for sure not reliable.

That said, the HttpServletRequest#getRemoteUser() returns the logged in user of the webapplication, not of the operaring system. Does that make sense now? The webapplication runs completely independent from the operating system. You should never imagine that they are related to each other somehow.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!