java 带有代码库的小程序 ClassNotFoundException

java applet ClassNotFoundException with codebase

我正着手开发一个小程序,它将取代现有的小程序。以前从未开发过 applet,我想我应该开始使用流行的 HelloWorld 示例。我能够 运行 它有几种不同的方式:在 appletviewer 中,如果我将包含 HelloWorld class 的 JAR 文件放在与 HTML 相同的目录中(即 http://localhost:8080/myApp)。当我将 JAR 放在 myApp 目录下方名为 HelloWorld 的目录中并将 <applet> 标记中的 codebase 参数指定为 HelloWorld 时,我也得到了它的工作。但是当我尝试指定 WEB-INF 目录时,例如 classeslib,我得到一个 ClassNotFoundException。我做错了什么?

But when I try to specify WEB-INF directories such as classes or lib, I get a ClassNotFoundException. What am I doing wrong?

这些目录仅用于 JSP 和 servlet(即服务器需要的东西)中使用的 classes/jars。其中的资源可供站点访问者使用。在这个意义上 'visitor' 表示用户代理(即浏览器)或客户端插件(例如 Flash 或 JRE)。

您可以自己确认这一点,方法是将完整的 URL 粘贴到 Web 浏览器地址栏中的 Jar 中,然后点击 'enter' 浏览器。服务端会回消息给大意'forbidden'.

另见 WEB-INF info. page 扩展:

WEB-INF is the name of a folder found in Java web applications. It is used to store deployment information such as the web.xml, required library files and compiled class files. It is normally not accessible from web. Any files which you want to put on war but do not want to make to public then web-inf is the place where you can keep those files.