permaculture playing cards*
The moose likes Servlets and the fly likes calling a Applet from a Servlet in Tomcat5 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 » Servlets
Bookmark "calling a Applet from a Servlet in Tomcat5" Watch "calling a Applet from a Servlet in Tomcat5" New topic
Author

calling a Applet from a Servlet in Tomcat5

Narendran Nair
Ranch Hand

Joined: Sep 25, 2003
Posts: 35
Hello guys
i got a small dought. i am trying to call a applet from a servlets doPost.
i gave the code as

out.println("<html><head>");//
out.println("<title> Server Page </title></head><body><br>");
out.println("<applet codebase = \"..//\"
code = \"com.myapplet.LaunchApplet.class\" name = \"TestApplet\"");
out.println("width = \"400\" height = \"300\" hspace = \"0\" vspace = \"0\" align = \"middle\">");
out.println("</applet></body></html>");


the servlet resides in the WEB-INF\classes\com\myapplet\LaunchApplet.class and the servlet resides in the WEB-INF\classes\com\myservlet\CalledServlet.class

the applet is working perfectly and it loads in the client side perfectly but when the applet is tried to load the explorer gives the following messages

----------------------------------------------------
load: class com.myapplet.LaunchApplet.class not found.
java.lang.ClassNotFoundException: com.myapplet.LaunchApplet.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed.
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)

can any one suggest a remedy for this .. i need to load the applet in the client side ...

I am using Tomcat5

hoping for a nice reply ...

thanking in advance

Narendran


Narendran J S<br />SCJP 1.4<br /><a href="http://narendranj.blogspot.com" target="_blank" rel="nofollow">http://narendranj.blogspot.com</a><br /><a href="http://narendranj.blogspot.com" target="_blank" rel="nofollow">http://techboom.blogspot.com</a><br /><a href="http://bookmarks-share.blogspot.com" target="_blank" rel="nofollow">http://bookmarks-share.blogspot.com</a>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
The browser is responsible for loading applet class files - it tries to get them from the server according to the codebase.
out.println("<applet codebase = \"..//\"
code = \"com.myapplet.LaunchApplet.class\" name = \"TestApplet\"");

However, your applet tag indicates that the browser should try to get the classes relative to the same address as it got the HTML page. That is the servlet address - the server is NOT ALLOWED to directly serve anything under WEB-INF therefore the browser gets the error. You have two choices:
1. create a servlet to serve the applet classes from WEB-INF
2. move your applet classes under the main web application directory and use codebase to point to them (or specify a BASE location in the HTML page.)

Bill
Narendran Nair
Ranch Hand

Joined: Sep 25, 2003
Posts: 35
thanks ..
i tried the second option.
i placed the applet and all the other things outside the web-inf folder

thanks

Regards
Narendran
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: calling a Applet from a Servlet in Tomcat5
 
Similar Threads
Error 404: File not found: loadservlet
Argh....all I want to do is load this applet..
Another Applet on Tomcat
java: ClassNotFoundException
Applet fetching problem in servlet