最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to find client computer name in java scriptjsp? - Stack Overflow

programmeradmin7浏览0评论

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 puter name? If so please give me example to do that? Thanks to all

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 puter name? If so please give me example to do that? Thanks to all

Share Improve this question asked Oct 19, 2010 at 0:42 vishnuvishnu 192 gold badges2 silver badges6 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

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

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

For MSIE on windows you can use this:

<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)

How to find this in java script or 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.)

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.

     <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.

发布评论

评论列表(0)

  1. 暂无评论