问题描述
我有一个Java小程序,查询数据的Oracle数据库。当从IDE中运行,它的功能就好了。但是当我运行它嵌入网页的小程序,我得到一个在类加载器访问被拒绝的错误,我一点都不知道概念它是什么,需要我的:
2011年9月6日下午12时58分48秒oracle.jdbc.driver.OracleDriver registerMBeans
警告:在注册的Oracle JDBC诊断性的MBean出错。
java.security.AccessControlException:访问被拒绝(java.lang.RuntimePermission,getClassLoader)
在java.security.AccessControlContext.checkPermission(来源不明)
在java.security.AccessController.checkPermission(来源不明)
在java.lang.SecurityManager.checkPermission(来源不明)
在java.lang.Thread.getContextClassLoader(来源不明)
在oracle.jdbc.driver.ClassRef<&初始化GT;(ClassRef.java:75)
在oracle.jdbc.driver.ClassRef.newInstance(ClassRef.java:51)
在oracle.jdbc.driver.OracleDriver.registerMBeans(OracleDriver.java:311)
在oracle.jdbc.driver.OracleDriver $ 1.run(OracleDriver.java:199)
在java.security.AccessController.doPrivileged(本机方法)
在oracle.jdbc.driver.OracleDriver< clinit>(OracleDriver.java:195)
在java.lang.Class.forName0(本机方法)
在java.lang.Class.forName(来源不明)
在com.binderton.oracle.ConnectionManager.open(ConnectionManager.java:17)
在com.sun.javafx.applet.FXApplet2 $ 2.run(来源不明)
在com.sun.javafx.application.PlatformImpl $ 3.run(来源不明)
在com.sun.glass.ui.win.WinApplication._runLoop(本机方法)
在com.sun.glass.ui.win.WinApplication.access $ 100(来源不明)
在com.sun.glass.ui.win.WinApplication $ 1 $ 1.run(来源不明)
在java.lang.Thread.run(来源不明)
java.lang.ExceptionInInitializerError
在java.lang.Class.forName0(本机方法)
在java.lang.Class.forName(来源不明)
在com.binderton.oracle.ConnectionManager.open(ConnectionManager.java:17)
在com.sun.javafx.applet.FXApplet2 $ 2.run(来源不明)
在com.sun.javafx.application.PlatformImpl $ 3.run(来源不明)
在com.sun.glass.ui.win.WinApplication._runLoop(本机方法)
在com.sun.glass.ui.win.WinApplication.access $ 100(来源不明)
在com.sun.glass.ui.win.WinApplication $ 1 $ 1.run(来源不明)
在java.lang.Thread.run(来源不明)
java.security.AccessControlException:引起访问被拒绝(java.lang.RuntimePermissiongetClassLoader)
在java.security.AccessControlContext.checkPermission(来源不明)
在java.security.AccessController.checkPermission(来源不明)
在java.lang.SecurityManager.checkPermission(来源不明)
在java.lang.Thread.getContextClassLoader(来源不明)
在oracle.jdbc.driver.ClassRef<&初始化GT;(ClassRef.java:75)
在oracle.jdbc.driver.ClassRef.newInstance(ClassRef.java:51)
在oracle.jdbc.driver.OracleDriver< clinit>(OracleDriver.java:260)
... 12更多
得到的ErrorEvent [URL =空标签=无法启动应用程序。导致= NULL
小程序符合非常严格的安全规则的环境中运行。你至少需要广告小程序。
不过,问题是在这里做大,做JDBC内的小应用程序是一个非常糟糕的主意。小程序的源$ C $ c是publicitly使用,适用于简单的黑客攻击这样的敏感。你真的应该创建一个web服务,而不是,然后让该web服务,而不是你的小应用程序的访问。随着Web服务,您的小程序将能够通过HTTP只是请求/响应与数据库交换信息。随着web服务隐藏DB访问的细节,JDBC和SQL code公众。
究竟如何创建一个web服务依赖于服务器环境和使用的编程语言。在Java EE例如,你可以使用已经为这个简单的Servlet,也是JAX-RS和JAX-WS分别支持REST风格(XML / JSON)和XML Web服务。 Applet是不会允许其主机,其地址可通过的例如
的InputStream响应=新的URL(获得codeBase的()的servlet富=酒吧?)的OpenStream()。
// ...
I have a java applet that queries an Oracle database for data. When run from inside an IDE, it functions just fine. But when I run it as an applet embedded in a webpage, I get an "access denied" error in the class loader, and I haven't the foggiest notion what it is requiring of me:
Sep 06, 2011 12:58:48 PM oracle.jdbc.driver.OracleDriver registerMBeans
WARNING: Error while registering Oracle JDBC Diagnosability MBean.
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.Thread.getContextClassLoader(Unknown Source)
at oracle.jdbc.driver.ClassRef.<init>(ClassRef.java:75)
at oracle.jdbc.driver.ClassRef.newInstance(ClassRef.java:51)
at oracle.jdbc.driver.OracleDriver.registerMBeans(OracleDriver.java:311)
at oracle.jdbc.driver.OracleDriver$1.run(OracleDriver.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.jdbc.driver.OracleDriver.<clinit>(OracleDriver.java:195)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.binderton.oracle.ConnectionManager.open(ConnectionManager.java:17)
at com.sun.javafx.applet.FXApplet2$2.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$1$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.binderton.oracle.ConnectionManager.open(ConnectionManager.java:17)
at com.sun.javafx.applet.FXApplet2$2.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$1$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" getClassLoader")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.Thread.getContextClassLoader(Unknown Source)
at oracle.jdbc.driver.ClassRef.<init>(ClassRef.java:75)
at oracle.jdbc.driver.ClassRef.newInstance(ClassRef.java:51)
at oracle.jdbc.driver.OracleDriver.<clinit>(OracleDriver.java:260)
... 12 more
Got ErrorEvent[url=null label=Failed to start application. cause=null
Applets runs in an environment with very restrictive security rules. You need at least to sign your applet.
But, the problem is bigger here, doing JDBC inside an applet is a very bad idea. The applet's source code is publicitly available and is thus sensitive for easy hacks. You should really create a webservice for that instead and then let your applet access that webservice instead. With a webservice, your applet will be able to exchange information with the DB by just HTTP requests/responses. With a webservice you hide the DB access details, JDBC and SQL code from the public.
How exactly to create a webservice depends on the server environment and the programming language used. In Java EE for example, you could already use a simple Servlet for this, but also JAX-RS and JAX-WS is supported for restful (XML/JSON) and XML webservices respectively. An applet is without any security restrictions allowed to connect with its host whose address is available by getCodeBase()
E.g.
InputStream response = new URL(getCodeBase(), "servlet?foo=bar").openStream();
// ...
这篇关于&QUOT;拒绝访问&QUOT;使用JDBC从浏览器小程序时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!