简体   繁体   中英

Use applet in Netbeans web application

<applet archive='AlienWar.jar' code='AlienWarApplet.class' width='387' height='410'>
                                </applet>

I have an applet and its works just fine when I use it in html and have the .jar in the same directory. But now I am building a web application in netbeans(I use JSF framework and Apache Tomcat server). I insert the same code in the index.xhtml and add the .jar to compile time libraries, but i get a classNotFoundExeception.

Where should I put the .jar??

The Jar needs to be in a place on the server where you could fetch it from if you typed the address in the browser address bar and hit Enter

For a web app., that particularly means. Do not put the archive in the WEB-INF/lib directory you might use for servlet/JSP libraries. That directory is not offered to the end user for browsing.

The code can be made to work by putting the archive in the same directory as the HTML (presuming the HTML is in a location that passes the 'fetch test'), but that is sloppy and might lead to the same Jar being in many directories for many applets.

Instead I would typically put all the applet archives in a single directory at the root of the domain. Specifically (no hard and fast rules here) lib . Specify codebase="/lib" in the applet element and the JRE will look in the http://your.com/lib path for whatever archives are in the comma separated list in the archive attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM