We are attempting Applet-Servlet communication. We seem to be doing
everything the books say on the subject, plus what we have seen in this
forum.

But it just isn't working.

Applet appears to be connecting to the servlet and writing the
object to the ObjectOutputStream (ie., we don't get any errors
when Applet performs these actions). But Servlet doesn't
seem to get the object we are sending. None of the debug messages
in the Servlet appear on the server console.

Our env:

Java 1.2, Java Web Server 2.0, SQLServer 6.5, NT Server 4.0

We used appletviewer to run the applet.

The Applet and Servlet code is attached below.

We would appreciate any pointers on what we could be doing
wrong.

It'd also greatly help us if someone would send as a complete set of
applet & servlet which work (ie., communicate with each other). We can
study the code and figure out what could be different in our case.

Thanks in advance.

-- Rali Panchanatham


APPLET CODE:


import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.net.*;
import java.util.*;

import com.rad.fire.dataobj.*;
import com.rad.fire.utility.*;

public class SampleApplet extends JApplet
{
 String URLStr = "/servlet/SampleServlet";
 objSchedule objSched = null;

 ...
 ...

                // read the host name from properties file
                ResourceBundle rs =
ResourceBundle.getBundle("LocalStrings");
                URLStr = "http://" + rs.getString("Fire.hostName") + ":8080"
+ URLStr;
                disp("Sample serv URL-"+URLStr);
 ...
 ...

                disp("writing schedule ..");
                try
                {
                        URL schedURL = new URL(URLStr);
                        URLConnection schedURLConn =
schedURL.openConnection();

                        disp(schedURL.toExternalForm());

                        schedURLConn.setUseCaches(false);
                        schedURLConn.setDefaultUseCaches(false);
                        schedURLConn.setDoInput(true);
                        schedURLConn.setDoOutput(true);
                        schedURLConn.setRequestProperty("Content-Type",
"application/octet-stream");


                        disp("Try to create outToServlet");

                        ObjectOutputStream outToServlet =
                                new
bjectOutputStream( schedURLConn.getOutputStream() );

                        disp("outToServlet created OK");

                        outToServlet.writeObject(objSched);

                        disp("writeObject OK");
                        outToServlet.flush();
                        outToServlet.close();

                        disp("writing complete");
                }
                catch(java.io.IOException e)
                {
                        disp(e.toString());
                }
        }

 ...
 ...


} //SampleApplet


SERVLET CODE:

import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import com.rad.fire.dataobj.objSchedule;
import com.rad.fire.dataobj.*;
import com.rad.fire.utility.*;


public class SampleServlet extends HttpServlet
{
        public static PrintWriter out;

        private clsSchedule mobjSchedule = null;
        private com.rad.fire.dataobj.objSchedule objsced = null;

 ResourceBundle resBundle = ResourceBundle.getBundle("LocalStrings");

        int countSchedule = 0;

    ...
    ...

        public void doGet
                (
                        HttpServletRequest request,
                        HttpServletResponse response
                )
                throws IOException, ServletException
        {

                boolean status = false;

                String title = "";
                String heading = "";
                String FormType = "";

                disp("Get ready to get param values...");

                ObjectInputStream input = null;

                disp("Before action");

                try
                {
                        input = new
ObjectInputStream(request.getInputStream());
                        objSchedule objSched =
(objSchedule)input.readObject();
                        input.close();

                        System.out.println("Sample Servlet-Schedule
Name-"+objSched.scheduleName+"-read from Applet");


                }
                catch(Exception e)
                {
                        disp(e.toString());
                }

        }

    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        doGet(request, response);
    }

    ...
    ...

} // Schedule Servlet

___________________________________________________________________________
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