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 a Applet from a Servlet in Tomcat5

 
Narendran Nair
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ..
i tried the second option.
i placed the applet and all the other things outside the web-inf folder

thanks

Regards
Narendran
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic