Access COM Port on Client Side in Web Programming Java

1.4k views Asked by At

I am developing a Web page using jsp and html where in I need to read/write from/to a Device connected on Client's System who are accessing the Webpage. The Device is a Serial Device which is connected as COM1(Eg) in Windows. I went through different options available. I found this which serves my purpose. I started learning JNLP for the same. I imported the project and made changes according to my needs. (This project is using jssc.jar). I generated the jar (jSSC-Terminal.jar) and signed with self-generated key. The GUI is being loaded properly but I am unable to access the Serial port on client's machine. Here is my jnlp file launch.jnlp

   <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp href="launch.jnlp" spec="1.0+"   codebase="http://192.168.1.33:8080/abc" 
    href="launch.jnlp">
    <information>
        <title>jSSC-Terminal</title>
        <vendor>scream3r</vendor>
        <homepage href="scream3r.org"/>
        <description>jSSC-Terminal</description>
        <description kind="short">jSSC-Terminal</description>

    </information>
<update check="background"/>
<security>
<all-permissions/>
</security>
    <resources>
<j2se version="1.5+"/>
<jar href="jSSC-Terminal.jar" main="true"/>

<jar href="jssc.jar" download="eager"/>



</resources>
    <applet-desc height="500" main-class="applet.Main" name="Main" width="700">

    <param name="separate_jvm" value="true"/>
<param name="draggable" value="true"/>
</applet-desc>
</jnlp>

Here is my html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
          <title>jSSC-Terminal</title>
            <style type="text/css">
              body {
                margin-left: 10px;
                margin-top: 10px;
                margin-right: 10px;
                margin-bottom: 10px;
              }
        </style>
        </head>
  <body>
  <applet code="applet.Main" archive="http://192.168.1.33:8080/abc/jSSC-Terminal.jar, http://192.168.1.33:8080/amar/lib/jssc.jar" width="700" height="500">
      <param name="separate_jvm" value="true"/>
      <param name="draggable" value="true"/>
          </applet>
        </body>
</html>

I have placed all these files in Tomcat directory as below

/Tomcat/webapps/abc/launch.jnlp
/Tomcat/webapps/abc/jSSC-Terminal.jar
/Tomcat/webapps/abc/index.html
/Tomcat/webapps/abc/lib/jssc.jar

I am unable to get the SerialPort List when run as jnlp. Kindly help me out with a fix if available. Or are there any alternate things available in JSP. Thanks and Regards.

Edit :

Finally found out thank you. I replaced my applet tag and included jnlp location as below :

<applet code="applet.Main" archive="http://192.168.1.33:8080/abc/jSSC-Terminal.jar,    http://192.168.1.33:8080/abc/lib/jssc.jar,"http://192.168.1.33:8080/abc/test.jnlp" width="700" height="500">
      <param name="separate_jvm" value="true"/>
      <param name="draggable" value="true"/>
          </applet>
        </body>
1

There are 1 answers

3
Dr.Haribo On BEST ANSWER

Your <applet> tag doesn't refer to the .jnlp file. You give access to COM ports in the jnlp file but it's not being used. You have to either use the jnlp file or set permissions in the <applet> tag.

Your link to the jssc example is a page that shows how to use the jnlp file from the <applet> tag.

I've done what you are trying to do with a Java Webstart app and the PureJavaComm library. I bet what you are doing will work once you get the permissions right, though. But if you want to have a look at how I set this up the jnlp file is here: https://bitminter.com/client/bitminter.jnlp (live app)