This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Calling an Applet from JSP - applet not inited? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Calling an Applet from JSP - applet not inited?" Watch "Calling an Applet from JSP - applet not inited?" New topic
Author

Calling an Applet from JSP - applet not inited?

Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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

Joined: Jan 15, 2002
Posts: 172
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling an Applet from JSP - applet not inited?
 
Similar Threads
A plugin is needed to display this content
web.xml andf default webapplication folder
Tomcat 4 : How to deploy and run JSP and Servlets
Where to put applet?
How to reference Applets in a Java Web Application