wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet-Applet communication problem 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 "Servlet-Applet communication problem" Watch "Servlet-Applet communication problem" New topic
Author

Servlet-Applet communication problem

Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
hi all,
this is my coding,
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class AppletViaServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException {
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
out.println("<html><head><title> Marketers Servlet Application </title></head>");
out.println("<body>");
out.println("<applet code=\"AppletEx.class\" width=500 height=200>");
out.println("</applet>");
out.println("</body></html>");
out.close();
}
}
The applet class "AppletEx.class" is kept inside app. directory 'MyServlets'(outside WEB-INF).
The AppletViaServlet.class in kept inside MyServlets/WEB-INF/classes as well.
My applet is running fine using appletviewer, but when i want to access thru servlet it is not getting initiated.
Need your suggestions pl. thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
When the browser sees this

It tries to download the class from the perceived location of the page.
In this case, that is based on the URL your servlet is addressed with.
The best thing to do is to not use the relative addressing but completely specify the location of the applet class. You might look into using the BASE tag in your HTML - that helps for locating images, CSS and other resources if you don't want your servlet to serve them directly.
Bill
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
thanks Mr.William,
could you give an example to make me clear?, thankyou.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
The base tag is used like this:

Now if the browser sees code="some.class" it will request /resources/some.class from the web server.
Same for images src="mypic.gif" will be requested as /resources/mypic.gif
Bill
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
thankyou very much Mr.William.
 
 
subject: Servlet-Applet communication problem
 
Similar Threads
Servlet HelloWorld problem
Servlet delivery in Tomcat
how to use ssi in servlets using apache web server and jserv
Applet-servlet communication
Applet fetching problem in servlet