问题
Just sharing some information hoping that it would be useful to the community.
Usability of Applets have gone down since various browsers stopped supporting plugins. Google has decided to discontinue support for NPAPI plugin, EDGE does not support plugins, Firefox is also discouraging use of plugins, and Mozilla may follow the suite.
One of the applications we developed required use of Applets for the following reasons
- Ability to access ports and peripheral devices attached to computing devices
- Ability to exchange information with the web application (Through JavaScript)
- Noninvolvement of System Administrators for installations and maintenance
- Application had to be launched from within the browser
The situation described earlier made us consider Java Web Start (JWS) technology as a potential alternative to Applet. JWS however came up with its own set of challenges due to its inability to communicate with the web application.
The solution (Applet) we had in place, would get a unique identifier from the web application; read data over serial ports; and submit the data to the web server along with previously received unique identifier. Rewriting a standalone application was not an option since the user community was as large as a typical B2C user community. Educating such a large community on using the application differently involved a lot of efforts and support staff. Developing a new application would also have involved significant efforts in terms of the product life cycle.
Adapting JWS had an advantage of reusing the code that was developed for Applet. However option to exchange information between Applet and Web Application with the help of Applet-JavaScript bridge was not available with JWS.
This is how we adapted JWS
User would access the web page that referred JNLP file containing details required to launch JWS application
The Web application would provide unique identifier to the JWS application via JNLP file
At this time the web application would start long polling/reverse AJAX. This was necessary since we had to notify success/failure results to the end user through web application
After reading information from a serial port, the JWS application would perform a HTTP POST and send readings along with UID as a parameter
Server would save the results and finish the long polling/reverse AJAX call; notifying web application the status of the operation
Shridhar
来源:https://stackoverflow.com/questions/39701341/can-an-applet-that-uses-javascript-to-communicate-with-web-server-be-migrated-to