wood burning stoves 2.0*
The moose likes Servlets and the fly likes where to store the applet file using JWS in servlet technology? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "where to store the applet file using JWS in servlet technology?" Watch "where to store the applet file using JWS in servlet technology?" New topic
Author

where to store the applet file using JWS in servlet technology?

honey singh
Ranch Hand

Joined: Apr 26, 2002
Posts: 44
I want to call applet from servlet using Java Web Server....so please tell me where can I store the applet class file and how to call the applet from servlet...
Thanking You in advance!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
You can't call an applet from a servlet, applets run on the browser, not the server. Assuming you mean that you want to have a servlet generate a page that has an applet in it, the thing to remember is that the browser has to request the applet code from the server, just like it has to request images, etc. Image and applet class files have to be put where the server can find them, just like when a normal html page with an image or applet is served.
The problem is that a page coming from a servlet looks to the browser like it is coming from an address that can't serve images and applet class files. The solution is to either:
1. give an absolute URL in the applet tag or
2. put a <base href="url_where_the_applet.class_files_are"> tag in the <head> area of the html page you build.
Bill
honey singh
Ranch Hand

Joined: Apr 26, 2002
Posts: 44
Hi William,
Thank You very much for the reply..but still the problem is persisting... actually the servlet is returning a page that has applet in it, now I had tried both of the options,like specifying the whole URL
<applet code="userinter.class" codebase="http://localhost:8080/public_html/student">
and same with the
<head>
<base href="same url as above">
</head>
but its giving the following error "java.lang.ClassNotFoundException:userinter.class"
any type of help will be appreciated.
Thank You!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
That looks like it should work. Is the userinter class in a package? If so you need to include the package name, and the codebase should point to the directory where the package starts.
code="mypkg.userinter.class" codebase="http://localhost:8080/public_html/student/">
where the class lives in:
server root/public_html/student/mypkg/userinter.class
Bill
honey singh
Ranch Hand

Joined: Apr 26, 2002
Posts: 44
Hi Bill,
Again thanx a lot for the reply, but the problem is still there...I'll now tell u the whole thing..I'm using JWS 1.1.3 now when I compile it using this, it says that it can't import javax package...so I'm compiling the servlet file and other files using Oracle JDeveloper and then copying the files from its directory to the directory of JWS...now I'm not using any packages, so then again the problem persists..and the whole code for the servlet is
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import oracle.sql.*;
import java.util.*;
public class input extends HttpServlet{

public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String registrationID = "";
HttpSession session = request.getSession(true);
registrationID=(String)session.getValue("registration");
response.setContentType("text/html");
PrintWriter out = new PrintWriter (response.getOutputStream());
out.println("<html>");
out.println("<body>");
out.println("<applet code=\"userinter.class\" codebase=\"http://its_78:8080/public_html/student/\" height=400 width=400>");
out.println("<param name=\"r1\" value=registrationID>");
out.println("</applet>");
out.println("</body>");
out.println("</html>");
out.close();
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
}
now the applet's class files are in
serverroot/pubic_html/student/userinter.class and also other files userinter$A,$B,$C,$D,$E which I had defined in the userinter.java file which contains these Classes A,B,C,D,E...and the userinter.java file is in the JDeveloper's directory...
so this is all .....
so again please help me..
Thank You!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
I would try to get the applet running from a static HTML page first. Once you have that, I would compare the source of the HTML page your servlet is writing versus the static page to see what is different.
For example, is your entire server running through port 8080? Your servlet code:
out.println("<applet code=\"userinter.class\" codebase=\"http://its_78:8080/public_html/student/\" height=400 width=400>");
indicates you expect it to be.
Bill
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at JavaRanch's naming policy. . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
honey singh
Ranch Hand

Joined: Apr 26, 2002
Posts: 44
Thank You very much for the reply again, now this time it worked..I just put the applet's class files in the public_html directory and wrote the tag as
<applet code="userinter.class" codebase="http://its_78:8080">
and vow it worked..
Thanx once again William for the favourable reply.
bye.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: where to store the applet file using JWS in servlet technology?