简体   繁体   English

带有摆动mysql和配置文件的applet在eclipse中有效,但在浏览器中失败

[英]applet with swing mysql and a config file works in eclipse but fails in browser

Hi it's probably because i'm a noob, but i'm trying to get this working for days now so hope that someone can help me.... 嗨,这可能是因为我是菜鸟,但我现在想让它工作几天,所以希望有人能帮助我...。

The idea: For a java training i need to make a Java applet that reads and writes data from a (localhost) MySQL database. 想法:对于Java培训,我需要制作一个Java 小程序 ,该程序可以从(本地)MySQL数据库读取和写入数据。 The settings from this database have to come out of a config.ini file. 该数据库中的设置必须来自config.ini文件。

The application runs fine as an applet and a java application in Eclipse. 该应用程序可以在Eclipse中作为applet和Java应用程序正常运行。 It also runs fine as an executable jar file. 它也可以作为可执行jar文件正常运行。

I can't get it running as an applet though...:(. 我不能让它作为小程序运行... :(。

The first error that i got was about reading the config.ini file. 我遇到的第一个错误是有关读取config.ini文件的。 I expect that this happens because of the security limitations (io). 我预计会由于安全限制(io)而发生这种情况。 It is something that needs to be solved but not my main concern for now. 这是需要解决的问题,但不是我目前主要关注的问题。

In order to see if the rest works i skip my loadIni class. 为了查看其余部分是否有效,我跳过了loadIni类。 Then i got a: driver not found exception. 然后我得到了:未找到驱动程序异常。 I solved this by loading the mySQL jar as an archive in my applet (). 我通过将mySQL jar作为档案加载到applet()中解决了这一问题。

But now i'm lost... 但是现在我迷路了...

When i start the applet in the browser i get the following error in the console: 当我在浏览器中启动小程序时,在控制台中出现以下错误:

java.lang.RuntimeException: java.lang.ExceptionInInitializerError
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at Kreta.DBConnection.<init>(DBConnection.java:39)
    at Kreta.AfhaalMenus.<init>(AfhaalMenus.java:21)
    at Kreta.test2.<init>(test2.java:39)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission"          
"file.encoding" "read")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
    at java.lang.System.getProperty(Unknown Source)
    at com.mysql.jdbc.StringUtils.<clinit>(StringUtils.java:70)
    ... 31 more

I really hope that somebody can send me in the right direction. 我真的希望有人可以向正确的方向发送我。

Applets are not allowed to do a number of things, including file I/O and various networking tasks; Applet不允许做很多事情,包括文件I / O和各种联网任务。 as your applet is trying to do one. 当您的小程序试图做一个。 You may need to sign you applet. 您可能需要在小程序上签名。

Check this reference 检查此参考

http://www.coderanch.com/how-to/java/HowCanAnAppletReadFilesOnTheLocalFileSystem http://www.coderanch.com/how-to/java/HowCanAnAppletReadFilesOnTheLocalFileSystem

The answer is signing all jars. 答案是在所有罐子上签名。

how to do this was still a quest but the following post made it really easy: 如何做到这一点仍然是一个探索,但以下文章使这变得非常容易:

how do i sign a java applet 我如何签署一个Java小程序

  1. An applet should not have direct access to the DB. 小程序不应直接访问数据库。 This is for the security of the DB. 这是为了保证数据库的安全。 Instead it should be forced to go through a web service that (limits what the user can do &) itself interacts with the DB. 相反,应该强制它通过一个Web服务,该Web服务(限制用户可以执行的操作&)本身与DB交互。
  2. An applet communicating with a DB (or a web service) on the same host that served it can be sand-boxed. 可以对与服务该服务器的主机上的数据库(或Web服务)进行通信的小程序进行沙盒处理。
  3. If that 'reading properties' error is part of the DB connection code you do not control, that is a good case for hiding the DB access behind the web service. 如果该“读取属性”错误是您无法控制的数据库连接代码的一部分,那么这是将数据库访问隐藏在Web服务之后的一个好案例。 Otherwise there are ways of reading a properties file (from the originating server) that do not invoke an AccessControlException . 否则,有一些方法(不从原始服务器)读取属性文件,而不会调用AccessControlException

Having said all that, it is getting to the stage where unsigned code is likely to be blocked before it is ever loaded, so perhaps the first thing you should do is digitally sign the applet and all required libraries. 综上所述,未签名的代码可能要在加载之前就被阻塞,所以您应该做的第一件事就是对小程序和所有必需的库进行数字签名。


Why code an applet? 为什么要编写小程序? If it is due to spec. 如果是由于规格。 by teacher, please refer them to Why CS teachers should stop teaching Java applets . 请向老师介绍为什么CS老师应该停止教Java小程序 This will be easier to do with a standard desktop app. 使用标准的桌面应用程序会更容易做到。 launched using Java Web Start . 使用Java Web Start启动 The security environment will be the same, but a free-floating app. 安全环境将相同,但是是自由浮动的应用程序。 is: 是:

  1. A better experience for the end user. 最终用户的更好体验。
  2. A lot easier to code and maintain than an applet embedded in a web page. 与嵌入在网页中的小程序相比,它更易于编码和维护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM