在 IE6 上的小程序中本地访问资源
试图遵循 http://java.sun.com/ docs/books/tutorial/uiswing/components/icon.html 遇到错误时。 在 IE6 中本地访问页面时(即,当 URL 为 "C:\projects\html\test.html"
时),getResource 似乎返回 null。 类和资源位于同一个 Jar 文件中。
有人知道原因和解决方法(如果存在)吗?
在Win XP/IE 6/JRE 1.6.0_11中遇到,但在Win XP/IE 7/1.6.0-b105中没有遇到。
在它工作的环境中,类加载器是:
sun.plugin.security.PluginClassLoader
在它损坏的环境中,它是:
sun.plugin2.applet.Applet2ClassLoader
Was trying to follow http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html when came across error. Seems that getResource returns null when accessing the page locally (i.e., when URL is, say, "C:\projects\html\test.html"
) in IE6. Class and resource are in same Jar file.
Anybody know the reasons and a work-around (if one exists)?
Encountered in Win XP/IE 6/JRE 1.6.0_11, but not in Win XP/IE 7/1.6.0-b105.
In the environment where it's working, the class loader is:
sun.plugin.security.PluginClassLoader
In the environment where it's broken, it's:
sun.plugin2.applet.Applet2ClassLoader
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您检查过 Java 控制台中的消息吗?
据我所知,Internet Explorer 6 比旧版 IE5 或 Netscape/Mozilla 具有更严格的安全规则。 虽然 Netscape 允许从本地驱动器打开的小程序访问该驱动器上的资源,但 IE 却不允许。 在这种情况下,您可能会在控制台中看到一些安全异常。
要解决此问题,请设置本地网络服务器,例如 Tomcat 并通过它访问包含小程序的 html 文件,例如 < a href="http://127.0.0.1:8080/some/applet.html" rel="nofollow noreferrer">http://127.0.0.1:8080/some/applet.html。 那么该小程序就不再来自您的硬盘,并且能够访问服务器 http://127.0 提供的任何资源。 0.1:8080/。
Did you check for messages in the Java Console?
As far as I remember Internet Explorer 6 has stricter security rules than older IE5 or Netscape/Mozilla. While Netscape allows applets opened from the local drive to access resources on that drive, IE does not. You might see some security exception in the console in this case.
To workaround set up a local webserver, e.g Tomcat and access the html file containing the applet through it, e.g. http://127.0.0.1:8080/some/applet.html. Then the applet is not from your harddist any more and is able to access any resource served by the server http://127.0.0.1:8080/.
本地运行的安全设置非常严格,请参阅安全报告 (提出类似问题在这里)。
正如另一个答案中所建议的,在网络服务器中运行它(例如tomcat),你的大多数问题应该是走了。
The security settings running locally is very restrictive, see security report (similar question asked here).
As suggested in another answer, run it in a web-server (eg tomcat) and most of your problems should be gone.
只是猜测:也许小程序安全限制在这里适用? 一般来说,除非小程序没有经过签名,否则不允许访问本地资源。 我不确定如果从本地存储的页面打开小程序,这是如何工作的,但这很可能是根本原因。
签署小程序并在浏览器中接受证书可能会解决问题。
Just a guess: Perhaps applet security limitations are applying here? In general, unless the applet is not signed, it is not allowed to access local resources. I'm not sure how this works if the applet is opened from a locally stored page, but it well may be the root cause.
Signing the applet an accepting the certificate in browser may solve the problem.
正如 Nick 提到的,Java 6 update 11 更改了在文件系统上运行的小程序的安全设置。 通过使用 getResource(),您从 URL 加载,并且可能意外地遇到了新的限制,而这些限制实际上并不适用于您。
尝试使用 getResourceAsStream() 代替,如下所示:
我还没有实际测试过这个,但我通常不会从文件系统运行小程序:)
As Nick mentioned, Java 6 update 11 changed the security settings for applets running on the filesystem. By using getResource() you are loading from a URL and may have accidentally bumped up against the new restrictions which shouldn't really apply to you.
Try getResourceAsStream() instead, like this:
I haven't actually tested this but I don't generally run applets from the filesystem :)
听起来不同之处在于您使用的是 "next- Generation" 插件1.6u10 中的技术。 您可以通过更改 Java 控制面板中“高级”选项卡下的相应选项来禁用它并使用旧的插件技术。 这至少可以将您的问题隔离到特定版本。
Sounds like the difference there is that you are using the "next-generation" plugin technology in 1.6u10. You can disable it and use the older plugin technology by changing the appropriate option under the Advanced tab in the Java Control Panel. That may at the very least isolate your problem to a particular version.