Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Struts - A MVC web framework
Tomcat - JSP/Servlet container
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
JSP - A mailing list about Java Server Pages specification and reference
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Problems with sending a serialized object from servlet to applet using Tomcat

Problems with sending a serialized object from servlet to applet using Tomcat

2003-12-15       - By Darina Dicheva.

 Back
Hello,

I have a problem sending a serialized object (instance of a class that is
not part of the Java Core API) from a servlet to an applet. I don't have a
problem to send a serialized String object though - everything works fine
(even in both directions). But when I replace the String object to be sent
by the servlet to the applet with an object of a class defined by me,
'inputFromServlet.readObject()' is just hanging -- no exception, no error,
nothing. The servlet itself seems to have finished its work completely. I
have copied the class definition (of the object being serialized) in the
applet's directory.

I use Tomcat 4.1.29 and j2sdk1.4.2.

Any idea will be highly appreciated. Thanks in advance.

Darina

-- ---- ---- ---- ----
In the applet I have:
try  {
         URL servletURL = new URL(getCodeBase(), servletLocation2);
         HttpURLConnection servletConnection = (HttpURLConnection)
servletURL.openConnection();
         servletConnection.setDoOutput(true);
         servletConnection.setDoInput(true);
         servletConnection.setUseCaches(false);
         servletConnection.setDefaultUseCaches(false);

servletConnection.setRequestProperty("Content-type","application/x-java-seri
alized-object");
         servletConnection.setRequestMethod("POST");     //if not included
the defaul is the GET method

         log("Applet Connected");

         // Writing to servlet

         // Write the message to the servlet
         OutputStream os = servletConnection.getOutputStream();  // returns
an output stream that writes to this connection
         ObjectOutputStream outputToServlet = new ObjectOutputStream(os);


         // serialize the object
    outputToServlet.writeObject("Message To Server");

    outputToServlet.flush();
    outputToServlet.close();
     log("Writing Complete.");

         // Reading from servlet

         InputStream is = servletConnection.getInputStream();
         ObjectInputStream inputFromServlet = new ObjectInputStream(is);
         log("Object Input stream created");

         Object obj = inputFromServlet.readObject();

// HANGS UP HERE !!

         Topic response = (Topic)obj;
         log("Finish reading data");
         inputFromServlet.close();
    }
    catch ...
-- ---- ---- ---- ----

In the servlet I have:

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

   try
   {
        InputStream is = request.getInputStream();   //get an input stream
that reads from from this open connection
        ObjectInputStream inputFromApplet = new ObjectInputStream(is);
        show("Servlet Connected");

   String appStr = (String) inputFromApplet.readObject();
   show("Applet String: " + appStr);
    inputFromApplet.close();

       // Ctreate a topic
        Topic topic = new Topic("Number1 Systems", "tt-NumberSystem1",
"N1", "Number1 System", "N1");
        show(topic.toString());

        response.setContentType("application/x-java-serialized-object");

        OutputStream os = response.getOutputStream();  // returns an output
stream that writes to this connection
        ObjectOutputStream outputToApplet = new ObjectOutputStream(os);
        show("Servlet connected");

        outputToApplet.writeObject(topic);
        outputToApplet.flush();
        outputToApplet.close();
        show("Data transmission complete.");

    }
    catch ...

Can somebody help??? I am struggling with this problem for more than a week
...

__ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ __
To unsubscribe, send email to listserv@(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



©2008 junlu.com - Jax Systems, LLC, U.S.A.