Happy New Year Everybody... i have a small problem in folloeing code code ----------------------------- import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import Test2; public class testsrevlet extends HttpServlet { public void init(ServletConfig config) throws ServletException { //Always pass the ServletConfig object to super class super.init(config); }
//Get Servlet information public String getServletInfo() { return "ex1 Information"; } } ---------------------------------------------- in the above code the applet is not getting invoked properly only the background is seen in the browser please help
The reason is that the browser is going to request the applet class files using a URL based on the servlet address!!! This is also the reason that <img tags in servlet generated pages frequently don't work. The best solution I know is to put a <base> tag in the <head> area of your generated page - this will tell the browser to request class files, image files, etc etc. from a URL that the web server knows. <base href="http://myserver/application/" > for example Bill
thanku Bill, is it possible to pass parameters from servlet to applet continuously i mean to say if i have a application in which i have a servlet which gets the value to person logged on and now i eant to pass it on to the applet to see the persons logged on is it possible. I also want the applet to be refreshed automatically so that all of them who are connected to site can see members logged on u can say as good as chat room but the applet should also be invoked from the servlet
thanku
------------------ Sagar Surana optimist
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12325
1
posted
0
Yes applets and servlets can communicate easily. Our host here at Javaranch has developed some classes for this which are pretty cool. Unfortunately I can't remember exactly where they are on this site so you will have to dig. Since the basic pattern of a servlet is to respond to a request with a response, the easiest thing is to have the applet query the servlet for new data. Bill
Hello Mr.Bill, Regarding ur explanation about base tag, could u explain how to specify href attribute tag value if my applet class file is available in the directory say c:\servlet. I've tried like this <base href=c:\servlet> But the browser doesn't load the applet class file and says that class file not found. I'm very happy if u will explain the solution for this problem. With regards Chandru
I do not know if this help but I managed to invoke an applet within one of the servlet I developed. Goto http://www.mycgiserver.com/servlet/smallalley.smallcon.jshitcounter.userlogin to have a look at the application. At the bottom of the application is the code for the applet. To put the applet in my servlet, I did what like what you have done:- out.println("<APPLET......"> and so on. If you can see the counter at the bottom, it means the applet is working from within the servlet.
Chandrasekaran Sathasivam
Greenhorn
Joined: Dec 29, 2000
Posts: 11
posted
0
Hai guys, Thanks for ur response. But both the replies didn't help me. I've specified the path like c:/servlet. But browser says the same error that class file not loaded. For the second reply the link http://www.mycgiserver.com/servlet/smallalley.smallcon.jshitcounter.userlogin hasn't connected. Could any body help me? What happen Mr.Bill? With regards Chandru
ray bond
Ranch Hand
Joined: Oct 11, 2000
Posts: 111
posted
0
the code that you have posted above in it you have written , <applet code=test.java..... you should write test.class, am i right.
Sagar Surana
Greenhorn
Joined: Dec 23, 2000
Posts: 21
posted
0
hello, sorry to say but the way u specified < Applet code=... in the servlet doesn't work with the browser instead it is better to invoke a html file for the applet from the servlet
------------------ Sagar Surana optimist
Sagar Surana
Greenhorn
Joined: Dec 23, 2000
Posts: 21
posted
0
Another small problem, i did connect applet and servlet invoking the html file from servlet for applet and then Forming URL connection with the servlet from applet to write and read objects my problem is that i am trying to pass a object( ofcouse serialized) which contains a java.awt.List object as its field the problem is when i do connection.getInputStream(); i get EOFException for io and it returns null i don't get the problem and could anybody explain me setRequestProperty( String key, String value) what does it do and what key and value mean in it.... preety urgent.. thnaku ------------------ Sagar Surana optimist
Mark Leong
Ranch Hand
Joined: Dec 11, 2000
Posts: 60
posted
0
Sometimes www.mycgiserver.com goes down. This is a free service so there is nothing much I could complain about. Try the link again. With the servlet, it should look something like:- out.println("<applet code=\"jshitcounterapplet.class\"\n"); out.println("codebase=\"http://www.mycgiserver.com/~smallalley/smallcon/jshitcounter/"\n"); ............... ........ Am not sure what you are trying to say in your last posting. Good luck.
Chandrasekaran Sathasivam
Greenhorn
Joined: Dec 29, 2000
Posts: 11
posted
0
Hai, Consider the following coding. It's concerned with calling an applet from servlet. import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Helloser extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); out.println("<html><head><h1>Hello World</h1>"); out.println("<base href=\"c:\\servlet\"></head>"); out.println("<applet code=hello.class height=400 width=400>"); out.println("</applet></html>"); out.close(); } } Here hello.class is the compiled code of the hello.java applet file, which is available in the directory c:\servlet. I've used servletrunner, jsdk application for this program. I've specified the address to see the page in browser like, http://localhost:8080/servlet/Helloser it calls the Helloser servlet and while loading hello applet class, it says that hello class not found. Here Helloser.java is the servlet file name available in the c:\servlet directory. What is wrong in the above code? Please explain. With regards Chandru
Mark Leong
Ranch Hand
Joined: Dec 11, 2000
Posts: 60
posted
0
Try placing the applet somewhere else (eg. directory where the html files are served) and not in the directory where the servlets reside.
Chandrasekaran Sathasivam
Greenhorn
Joined: Dec 29, 2000
Posts: 11
posted
0
Hai, I've done what u say. ie., placing applet file in another directory. But still the same problem exists. I've put my applet in c:\javasrc dir. and change the href attribute of base tag as c://javasrc. Could u help me. With regards Chandru
Mark Leong
Ranch Hand
Joined: Dec 11, 2000
Posts: 60
posted
0
Lets take it step by step. First, the applet should be test.class, not test.java. Can you invoke the applet from a html page (not from servlet)? Try placing the applet in the default directory where the html pages are served out from your server. Can other applets work or the problem is common to all applets on the server? Try restoring the default setting for your server and see if problem is still there. Have fun.
Hay, Thanks all guys. I've got the result for calling applet from servlet. It perfectly works by placing codebase attribute with applet tag, that what sunilkumar told. Once again I thank to all guys response my request. With regards Chandru