I have a java applet that I would like to include in my ASP.NET page. The applet works on a 开发者_如何学Pythonregular old HTML page. When I try to include the applet in my ASP.NET page however, Java appears to start up (it shows the Java logo and the spinny blue circle), but an exception occurs for my main class:
load: class com.myclass.Main.class not found.
java.lang.ClassNotFoundException: com.myclass.Main.class
I am putting the applet in the page with the following code -
<applet
code="com.xyz.Main.class"
width="500" height="500"
archive="MyJar.jar"
>
<param name="aParam" value="SomeValue"/>
</applet>
Note, this is exactly the same tag that I use to put the applet into a plain HTML page. I'm guessing that the reason for the class not found exception is that when ASP compiles the page it puts it somewhere else? If so, where? Note that I still have not actually deployed this page to a web server, it's just running locally on my development machine.
Why not simply specify an absolute URI/oath to your applet with the codebase attribute? That way you would not have to worry about the vagaries of relative pathing of different systems.
Also see here for a longer explanation. Excerpt:
Specifying the Applet Directory
By default, a browser looks for an applet's class and archive files in the same directory as the HTML file that has the tag. (If the applet's class is in a package, then the browser uses the package name to construct a directory path underneath the HTML file's directory.) Sometimes, however, it's useful to put the applet's files somewhere else. You can use the CODEBASE attribute to tell the browser in which directory the applet's files are located:
<APPLET CODE=AppletSubclass.class CODEBASE=aURL
WIDTH=anInt HEIGHT=anInt>
</APPLET>
If aURL is a relative URL, then it's interpreted relative to the HTML document's location. By making aURL an absolute URL, you can load an applet from just about anywhere -- event from another HTTP server.
- Create a simple Java Applet.
- Create a default web application.
- Copy the Applet.class file to the web application folder.
- Add a default user control to the web application.
- Add the following HTML code in the user control.
<applet name="applet" code="applet.class" width="640" height="480" archive="applet.jar"
> <param name="foreground" value="FFFFFF"/>
> <param name="background" value="008080"/>
> <param name="label" value="This string was passed from the HTML host."/> </applet>
Build and run the web application
And don't forget to add java.policy.applet. cheers, :)
精彩评论