作者averywu (看文不要只会用横的看)
看板Ajax
标题[问题] Java Applet 传回值
时间Mon Dec 6 15:57:29 2010
我有一支Applet,会 System.out.string 回来。
我在HTML宣告这支Applet了。
但是在我alert(document.GetHardwareAddress.gma());时。
会说
There is no static Java method GetHardwareAddress.
gma that matches JavaScript argument types ().
Candidate methods with the same name are: void gma(java.lang.String[])
我的APPLET如下:
import java.net.*;
import java.util.Enumeration;
import java.applet.*;
public class GetHardwareAddress extends Applet{
public static void main(String args[]) throws Exception {
Enumeration interfaces = NetworkInterface.getNetworkInterfaces();
String sstr = "";
String sep = ":";
while (interfaces.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) interfaces.nextElement();
NetworkInterface networkInterface = NetworkInterface.getByName(ni.getName());
byte[] b1 = networkInterface.getHardwareAddress();
if (b1!=null){
for (int i = 0; i < b1.length; i++){
if(i == 5){ sep = ""; }
sstr = sstr + byteHEX(b1[i])+sep;
}
}
}
sstr = sstr.toUpperCase();
System.out.print(sstr+"\n");
}
public static String byteHEX(byte ib) {
char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a','b', 'c', 'd', 'e', 'f' };
char[] ob = new char[2];
ob[0] = Digit[(ib >>> 4) & 0X0F];
ob[1] = Digit[ib & 0X0F];
String s = new String(ob);
return s;
}
}
JAVASCRIPT & HTML 如下:
<html>
<head></head>
<body>
<!--[if !IE]> Firefox and others will use outer object -->
<embed type="application/x-java-applet"
name="GetHardwareAddress"
ID = "GetHardwareAddress"
width="0"
height="0"
code="GetHardwareAddress"
archive="GetHardwareAddress.class"
pluginspage="
http://java.sun.com/javase/downloads/index.jsp"
style="position:absolute; top:-1000px; left:-1000px;">
<noembed>
<!--<![endif]-->
<!---->
<object classid="clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA"
type="application/x-java-applet"
name="GetHardwareAddress"
ID = "GetHardwareAddress"
style="position:absolute; top:-1000px; left:-1000px;">
<param name="code" value="GetHardwareAddress">
<param name="archive" value="GetHardwareAddress.class" >
<param name="mayscript" value="true">
<param name="scriptable" value="true">
<param name="width" value="0">
<param name="height" value="0">
</object>
<!--[if !IE]> Firefox and others will use outer object -->
</noembed>
</embed>
<!--<![endif]-->
<script type="text/javascript">
function showme(){
alert(document.GetHardwareAddress.gma( ));
}
</script>
<input type = "Button" onclick="showme();" value = "Get MAC Address">
</body>
</html>
我该修改什麽地方呢? 感谢 !
--
小恶魔的家
http://blog.pixnet.net/shiuju/
--
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.124.142.152
※ averywu:转录至看板 java 12/06 15:58
1F:→ Kelunyang:那个...我觉得为了防止伪造,你不要用js去回传MAC 12/07 08:45
2F:→ Kelunyang:用开发工具就可以看到你的整个回传动作了 12/07 08:46
3F:→ Kelunyang:这样有防跟没防一样,直接在applet里回传吧! 12/07 08:46
5F:→ Kelunyang:这是silverlight读MAC的方式,你如果applet遇到安全性 12/07 08:55
6F:→ Kelunyang:问题,还是换别招吧,网路的安全性还是比单机程式高 12/07 08:55