[英]Reading client COMPORT from Java applet
I need to read client comport accessing my JSP based web application. 我需要阅读客户端命令来访问基于JSP的Web应用程序。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>COMPORT</title>
</head>
<body bgcolor="blue">
<h1>ACCESSING COMPORT</h1>
<jsp:plugin align="middle" height="500" width="500" type="applet" archive="" code="SunCommSerialPort.class" name="clock" codebase="."/>
</body>
</html>
This is my Java applet code to read COM port. 这是我的Java applet代码,用于读取COM端口。
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
/** @author Venugopal */
public class COMPORT {
/** @param args the command line arguments */
public static void main(String[] args) {
COMPORT CM = new COMPORT();
String StrCommPort = CM.GetSerialPort();
System.out.println("StrCommPort " + StrCommPort);
}
public String GetSerialPort() {
String Serialport = "";
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
Serialport = Serialport + portId.getName() + "//";
} else {
// ////////////System.out.println(portId.getName());
}
}
if(Serialport !=null && Serialport.length() >0){
Serialport = Serialport.substring(0, Serialport.length() - 2);
}
return Serialport;
}
}
Please tell us what to do.I have kept all necessary files at correct place. 请告诉我们该怎么办。我已将所有必要的文件保存在正确的位置。 The Java code I have kept here was working after that I have modified extending applet and removing PSVM with
init()
method. 在修改了扩展小程序并使用
init()
方法删除PSVM之后,我保留在此处的Java代码开始工作。
You need to give the applet permission, there are several ways to achieve that. 您需要授予applet权限,有几种方法可以实现。 There should be a stacktrace telling you more.
应该有一个stacktrace告诉您更多信息。
I am somewhat surprised you can sign an applet but don't understand the example, anyway in your jsp applet tag 我有点惊讶您可以签署一个applet,但无论如何在您的jsp applet标记中还是不理解该示例
<PARAM NAME="MAYSCRIPT" VALUE="true">
make a javascript function eg 做一个JavaScript函数,例如
myfunc(comport){
//do stuff
}
in the applet something like 在小程序中像
JSObject.getWindow(this).call("myfunc",comport);
or 要么
JSObject.getWindow(this).eval("myfunc("+comport+")");
Also there is DOMService but I never used that, it is more typed but your javascript method will not be there anyway 也有DOMService,但我从未使用过,它的类型更多,但是您的javascript方法将永远不会出现
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.