Hi,
What exception do you get? Is that a Security exception?
Browsers does not support JDK1.2. They need Plug-in.
Regards.
>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