javascript 如何在java script/jsp中查找客户端计算机名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3964595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 02:50:39  来源:igfitidea点击:

How to find client computer name in java script/jsp?

javajavascriptjsp

提问by vishnu

My print application has to get the client name and then print the documents. How to find this in java script or jsp? I searched here. Some are discussing on PHP and so? Something discussed about running secure applet to get the client computer name? If so please give me example to do that? Thanks to all

我的打印应用程序必须获取客户端名称,然后打印文档。如何在java脚本或jsp中找到它?我在这里搜索过。有些人在讨论PHP等等?讨论了有关运行安全小程序以获取客户端计算机名称的内容吗?如果是这样,请给我一个例子来做到这一点?谢谢大家

回答by Júlio Santos

You can't do it with Javascript. Try building a Java applet and:

你不能用 Javascript 来做到这一点。尝试构建一个 Java 小程序,然后:

java.net.InetAddress i = java.net.InetAddress.getLocalHost();
System.out.println(i.getHostName());

回答by Dr.Molle

For MSIE on windows you can use this:

对于 Windows 上的 MSIE,您可以使用:

<script type="text/jscript">
<!--
var net = new ActiveXObject("WScript.Network");
alert(net.ComputerName);
//-->
</script>

...but: the page has to be "trusted"!(and of course jscript is not javascript)

...但是:页面必须是“可信的”!(当然 jscript 不是 javascript)

回答by Stephen C

How to find this in java script or jsp?

如何在java脚本或jsp中找到它?

You cannot do this in a JSP, because the JSP executes on the server side. (In theory a JSP could try to determine the client IP address from the request object via the getRemoteAddr()method, but this will fail if the user's browser accesses the server via a web proxy.)

您不能在 JSP 中执行此操作,因为 JSP 在服务器端执行。(理论上,JSP 可以尝试通过该getRemoteAddr()方法从请求对象中确定客户端 IP 地址,但是如果用户的浏览器通过 Web 代理访问服务器,这将失败。)

回答by Sai Ye Yan Naing Aye

I don't think that's possible using only JSP. I believe you'll need to execute some code on the client, and that code will probably need to be signed.You may be able to do it by included a signed applet that executes on the client PC and then sends the relevant information to your server. You might also be able to do it with JScript or VBScript.Here's the code to get windows username in javascript.

我认为仅使用 JSP 是不可能的。我相信您需要在客户端上执行一些代码,并且该代码可能需要签名。您可以通过包含在客户端 PC 上执行的签名小程序然后将相关信息发送到您的服务器。您也可以使用 JScript 或 VBScript 来完成此操作。这是在 javascript 中获取 Windows 用户名的代码。

     <script language="javascript" type="text/javascript">
         var WshNetwork = new ActiveXObject("WScript.Network");
         alert (WshNetwork.UserName);
     </script>

This code snippet will work only in Internet Explorer because Internet Explorer deals with ActiveX Controls.

此代码段仅适用于 Internet Explorer,因为 Internet Explorer 处理 ActiveX 控件。