0

I need to read client comport accessing my JSP based web application.

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

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.

4

1 回答 1

0

您需要授予小程序权限,有几种方法可以实现。应该有一个堆栈跟踪告诉您更多信息。

我有点惊讶你可以签署一个小程序但不理解这个例子,无论如何在你的 jsp 小程序标签中

<PARAM NAME="MAYSCRIPT" VALUE="true">

制作一个javascript函数,例如

myfunc(comport){
    //do stuff
}

在小程序中类似

JSObject.getWindow(this).call("myfunc",comport);

或者

JSObject.getWindow(this).eval("myfunc("+comport+")");

还有 DOMService 但我从未使用过它,它的类型更多,但您的 javascript 方法无论如何都不会存在

于 2013-09-10T23:02:33.147 回答