applet与mysql通信时的java.security.AccessControlException

时间:2022-06-01 23:04:47

My school's programming club is starting a tutoring program, and I have built a Java applet that students can use to request sessions. The applet communicates with a database that has a table that stores the availability of the tutors, and shows the user the available times.

我的学校的编程俱乐部正在开始辅导计划,我已经构建了一个Java applet,学生可以使用它来请求会话。 applet与具有存储教师可用性的表的数据库通信,并向用户显示可用时间。

First off: I know it's a bad idea to have an applet communicate directly with a database, for security reasons. That being said, this is a fairly low-risk situation (nothing "sensitive" is stored on the database), and this solution is only temporary (we don't currently have a server capable of running tomcat, so everything needs to be done client-side).

首先:出于安全原因,我知道让applet直接与数据库通信是一个坏主意。话虽这么说,这是一个相当低风险的情况(没有“敏感”存储在数据库中),这个解决方案只是暂时的(我们目前没有能够运行tomcat的服务器,所以一切都需要完成客户端)。

The applet GUI loads correctly, but throws a java.security.AccessControlException ("java.lang.RuntimePermission" "setContextClassLoader") exception when it initializes the class that tries to access the database, and no data is loaded. How can I solve this problem?

applet GUI正确加载,但在初始化尝试访问数据库的类时,抛出java.security.AccessControlException(“java.lang.RuntimePermission”“setContextClassLoader”)异常,并且未加载任何数据。我怎么解决这个问题?

EDIT: I've changed my code so that the DB communications occur on the same thread as the GUI. Now I'm getting this exception:

编辑:我已经更改了我的代码,以便数据库通信发生在与GUI相同的线程上。现在我得到了这个例外:

Exception in thread "Thread-46" java.lang.NoClassDefFoundError: Could not initialize class com.mysql.jdbc.StringUtils
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:298)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at helpsessions.DBHandler.run(DBHandler.java:53)
at java.lang.Thread.run(Unknown Source)

1 个解决方案

#1


0  

Applets have a very restricted security model by default, in order to extend the facilities available to the applet you will need to sign the applet, and then write an updated security policy with the extended permissions you require.

默认情况下,Applet具有非常有限的安全模型,为了扩展applet可用的设施,您需要对applet进行签名,然后使用所需的扩展权限编写更新的安全策略。

Your second problem - class not found - is because the driver is not being distributed with the applet.

你的第二个问题 - 找不到类 - 是因为驱动程序没有与applet一起分发。

I found this with reference to Java 1.1.

我发现这是参考Java 1.1。

If you're using an applet, then you must place those JARs and class files in the applet's codebase directory and/or archive locations

如果您正在使用applet,那么您必须将这些JAR和类文件放在applet的codebase目录和/或归档位置中

I'm not sure how relevant is to the latest versions of Java, but I would suggest that is your best option to make the driver Jar available to the applet.

我不确定与最新版本的Java有多相关,但我建议这是让applet可以使用驱动程序Jar的最佳选择。

#1


0  

Applets have a very restricted security model by default, in order to extend the facilities available to the applet you will need to sign the applet, and then write an updated security policy with the extended permissions you require.

默认情况下,Applet具有非常有限的安全模型,为了扩展applet可用的设施,您需要对applet进行签名,然后使用所需的扩展权限编写更新的安全策略。

Your second problem - class not found - is because the driver is not being distributed with the applet.

你的第二个问题 - 找不到类 - 是因为驱动程序没有与applet一起分发。

I found this with reference to Java 1.1.

我发现这是参考Java 1.1。

If you're using an applet, then you must place those JARs and class files in the applet's codebase directory and/or archive locations

如果您正在使用applet,那么您必须将这些JAR和类文件放在applet的codebase目录和/或归档位置中

I'm not sure how relevant is to the latest versions of Java, but I would suggest that is your best option to make the driver Jar available to the applet.

我不确定与最新版本的Java有多相关,但我建议这是让applet可以使用驱动程序Jar的最佳选择。