First of all, the only chance of this ever working(if any), is if you run the
browser on the same machine that has the Webserver and applet. Since you
use localhost, that will always refer to the local m/c. If this is indeed
the way
you have it, then you may need to check to see that the machine has
connection
permissions set to listen,accept..


At 05:24 PM 05/25/2000 +0000, ajaikumar peddapanga wrote:
>Have a doPost() in your servlet and let it call doGet() passing the
>req and the res in to it ...
>Also u can check the request method in your applet by calling
>getRequestMethod() on the connection object.
>
>cheers
>
>
>
>>From: Shaila C D <[EMAIL PROTECTED]>
>>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
>>        Servlet API Technology." <[EMAIL PROTECTED]>
>>To: [EMAIL PROTECTED]
>>Subject: Applet-Servlet communication
>>Date: Thu, 25 May 2000 14:45:35 +0530
>>
>>Hi,
>>
>>   I am facing a problem with the communication between an Applet and a
>>Servlet. This code works fine if the applet is run from an appletviewer,
>>however, the applet does not fetch the same result when it is run on the
>>browser. Instead, it throws an exception. The code is attached below. The
>>whole exercise is to get the time from the server. I am using JSDK2.0,
>>JDK1.2 and servletrunner to load the servlet.
>>Let me know if I am missing anything
>>
>>Thanks.
>>
>>Applet Code
>>--------------------
>>
>>import java.applet.Applet;
>>import java.net.*;
>>import java.io.*;
>>import java.io.Reader.*;
>>import java.awt.*;
>>
>>public class client extends Applet {
>>
>>   URL url = null;
>>   public void init() {
>>    try {
>>     url = new URL("http://localhost:8080/servlet/survey");
>>    }catch(MalformedURLException e) {
>>     System.out.println("exception URL");
>>    }
>>   }
>>
>>   public void start() {
>>     repaint();
>>   }
>>
>>   public void paint(Graphics g) {
>>     g.drawString(getDate(),50,50);
>>   }
>>
>>   public String getDate() {
>>    try {
>>      URLConnection con = url.openConnection();
>>      con.setDoInput(true);
>>      con.setDoOutput(true);
>>      con.setUseCaches(false);
>>      InputStream in = con.getInputStream();
>>      BufferedReader dis = new BufferedReader(new InputStreamReader(in));
>>      String date = dis.readLine();
>>      in.close();
>>      return date;
>>    }catch(Exception e) {
>>      System.out.println("exception");
>>      return null;
>>    }
>>   }
>>}
>>
>>Servlet code
>>-------------------
>>import java.util.*;
>>import javax.servlet.http.*;
>>import javax.servlet.*;
>>import java.io.*;
>>
>>public class SurveyServlet extends HttpServlet {
>>   public void init(ServletConfig config) throws ServletException {
>>     super.init(config);
>>   }
>>
>>   public void doGet(HttpServletRequest req, HttpServletResponse res) {
>>     res.setContentType("text/html");
>>     try {
>>       PrintWriter toClient = res.getWriter();
>>       toClient.println(new Date().toString());
>>     }catch(IOException e) {
>>        System.out.println("exception");
>>     }
>>   }
>>}
>>
>>HTML
>>-----------
>><html>
>><body>
>><applet code=client height=200 width=300> </applet>
>></body>
>></html>
>>
>>Servlet.properties
>>------------------------------
>>servlet.survey.code=SurveyServlet
>>
>>___________________________________________________________________________
>>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>>of the message "signoff SERVLET-INTEREST".
>>
>>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>>Resources: http://java.sun.com/products/servlet/external-resources.html
>>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>________________________________________________________________________
>Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>


Rajesh Nair
[EMAIL PROTECTED]
Ph: 913 599 7201

----------
R&D
Informix Software

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to