Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Calling an Applet from JSP - applet not inited?

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having problem to initiate my applet,
e.g. is it possible to have JSP page outside WEB-INF
to call an applet class that is inside WEB-INF?



And I have in MyJSPApplet.jsp:

I get no error, just a message: applet not inited from my browser.
[ October 12, 2004: Message edited by: Velika Srbija ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm having problem to initiate my applet,
e.g. is it possible to have JSP page outside WEB-INF
to call an applet class that is inside WEB-INF?


Short answer NO
The whole design of the servlet API is intended to keep the data under WEB-INF hidden from browsers. It is illegal for a server to directly serve anything under WEB-INF - it is a very important security restriction.
Your choices are:
1. Put your applet classes where the browser is allowed to request them - just like you were supporting an applet in a static HTML page.
2. Create a servlet to serve the applet classes from the WEB-INF location.
Bill
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you give me some guidelines on how to serve an applet class from my servlet?
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Serving an applet class is just like serving any other binary data from a file - the request is going to be a GET.
you have to be sure to
1. use the response OutputStream (NOT the writer)
2. set the content-type to match what the browser is expecting (I can't remember what the type is for class files)
3. set the content-length to the actual length of the binary data - you can get that from the File length() method
4. read the file into a byte[] buffer and write it to the response output stream
5. close the output stream
6. be sure to catch and log any IOExceptions
Bill
reply
    Bookmark Topic Watch Topic
  • New Topic