Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling an Applet from JSP - applet not inited?

 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • 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 ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic