使用 JAVA 或 JSP 获取 Windows 用户名 [英] Get windows username using JAVA or JSP

查看:57
本文介绍了使用 JAVA 或 JSP 获取 Windows 用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 windows 上登录用户名,我的意思是用户使用 java 登录到 windows.我用了System.getProperty("user.name"); 但我得到了服务器名称,而不是用户.

I want to get logged username on windows , I mean the user logged in to windows using java. I used System.getProperty("user.name"); but I got the server-name, not the user.

推荐答案

获取登录到您的 Web 应用程序的用户的名称(根据您的评论,我认为这是您想要做的)完全取决于您的方式在您的系统中实施身份验证.但是,如果您的登录机制添加了此信息,则用户名可能在 request.getRemoteUser()request.getUserPrincipal().但如前所述,这一切都取决于.否则,您的身份验证机制可能会暴露这一点,但随后我们需要更多信息来提供帮助.

Getting the name of the user logged into your web application (which I think is what you want to do, based on your comments) entirely depends on how you have implemented authentication in your system. However, if your login mechanism adds this information, the username might be available in request.getRemoteUser() or request.getUserPrincipal(). But as mentioned, it all depends. Your authentication mechanism might expose this otherwise, but then we would need more information to assist.

System.getProperty("user.name") 只会给你运行 java 进程的用户的用户名.

System.getProperty("user.name") will only give you the username of the user running the java process.

这篇关于使用 JAVA 或 JSP 获取 Windows 用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆