Leonard Wolters wrote:
>
> Hi there,
>
> I still have problems with loading applets within jsp pages.
>
> Consider the following scenario:
> I have a WAR file which consists of several .jsp files, a "WEB-INF"
> directory which contains a "classes" and a "lib" directory. In the classes
> directory, another directory "foo" exists which contains the "BarApplet.class" file.
>
> >From one of the jsp files, i try to load the applet using the following
> code:
>
> <jsp:plugin
>   type="applet"
>   code="foo.BarApplet.class"
>   codebase="/"
>   jreversion="1.3"
>   align="center"
>   height="400"
>   width="400"
>   nspluginurl="http://java.sun.com/products/plugin/1.3.0_01/plugin-install.html";
>   
>iepluginurl="http://java.sun.com/products/plugin/1.3.0_01/jinstall-130_01-win32.cab#Version=1,3,0,1";
> >
>
>   <jsp:fallback>
>     <p>Unable to start plugin.</p>
>   </jsp:fallback>
> </jsp:plugin>
>
> Still, each time the java console tells me that the file foo.BarApplet.class cannot 
>be found. Even after changing the codebase
> from relative to full (i.e. http://) it still doesn't work out.
>
> The only thing that works is to copy the "web-inf\classes\foo" directory
> to the 'root' of the WAR file i.e. the place where all .jsp files are
> located. Then, I finally see the applet showing up...
>
> The only thing that I can figure out is that the "web-inf\classes" is
> unaccessable from the web --> it is unvisible.

Yes, that's exactly what the servlet specification demands. Contents in the
WEB-INF directory structure must not be accessible to clients, only to
code running on the server. The applet code is loaded directly by the
browser, so it must be located in a publicly accessible directory,
defined by the codebase attribute.

Also note that HTML 4.0 requires that the codebase directory be a subdirectory
of the directory where the web page is located. So if you have the JSP
page /foo/bar.jsp, you could specify codebase as "classes" and place the
applet class files in /foo/classes.

> Can someone please help me out by telling me how they succeeded in
> showing applets from jsp pages ? Do I need to explicitly create a jar
> file containing the applet ?

No, you can put the class files directly in the directory specified by
codebase.

> Or can i use the web-inf\classes directory ?
> (preferable). Or do I just need to put the classes in the 'root' directory ?

See above; you can *not* put them in any WEB-INF subdirectory.

> Please help me out !
>
> (I know for sure that it should be possible to access the applet from the
> web-inf\classes directory from a jsp file)

I don't know where you've got this information, but it's contrary to what
the spec says (and as you have found, how it works in real life :-)

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to