在 Web 应用程序中运行小程序 [英] run applet in web application

查看:31
本文介绍了在 Web 应用程序中运行小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 html applet 标签在我的 web 应用程序中运行简单的小程序,但它给出了像

I want to run simple applet in my web application using html applet tag but it gives error like

java.lang.ClassNotFoundException: MyApplet

java.lang.ClassNotFoundException: MyApplet

如果可能,请给我示例应用程序.....

please, give me sample application if possible .....

推荐答案

问题是小程序引擎无法在您定义的代码库中找到您的 MyApplet 类.

the problem is that the applet engine can't find your MyApplet class at the codebase you have defined.

这可能是因为您在/WEB-INF/classes 目录中设置了课程.该目录受 servlet 引擎保护,因为它不能从外部资源访问(可以是 JSP/HTML 页面上的小程序标记.

This can be caused because you have you class at your /WEB-INF/classes directory. This directory is protected by the servlet engine, for it not to be accesed from external resources (as can be an applet tag at a JSP/HTML page.

有几种方法可以解决这个问题.最简单的方法是将您的 MyApplet 类打包成一个 jar 文件(我们称之为 myapplet.jar),并将其保存在一个可访问的目录中(即您的 Web 应用程序的 jsp 文件夹).例如,假设您有以下 Web 应用程序文件夹:

There are a few ways to solve this. The easiest one is to pack your MyApplet class un a jar file (let's call it myapplet.jar), and save it at an accesible directory (i.e. the jsp folder of your web application). As an example, supose you have the following folders for the web application:

/MyWebApp/jsp
/MyWebApp/applet
/MyWebApp/WEB-INF

客户端浏览器可以访问jsp和applet文件夹的内容.

The client browsers can access the content of jsp and applet folders.

然后,将您的 myapplet.jar 保存在小程序文件夹中,并像这样设置您的小程序标签配置(假设您的网络上下文是 MyWebApp):

Then, save your myapplet.jar at the applet folder, and set your applet tag configuration like this (suposing that you web context is MyWebApp):

<applet codebase="/MyWebApp/applet" archive="myapplet.jar" 
        code="MyApplet.class" width="600" height="500">
</applet>

您可以在此处找到有关小程序标记的更多信息:http://docs.oracle.com/javase/tutorial/deployment/applet/index.html

Here you can find more info about the applet tag: http://docs.oracle.com/javase/tutorial/deployment/applet/index.html

这篇关于在 Web 应用程序中运行小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆