Continuously send serialized objects from servlet

Hi,
I'm trying to write a servlet that, once activated, will continuously send objects back to a thread in the client. I'm hoping someone can point me in the right direction. This code works fine if you take out the while(true){...} loops.
After doing a bit more research, I discovered the OutputObjectStream should be .reset() in order to reset the object map. I tried doing this before the .flush() with no success. The servlet continues to spew out objects, but the client side doesn't even see the first one, hanging on the in = DataInputStream(connection.getInputStream()) line.
Servlet code:
public class testStream extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
int[] somedata = new int [1];
somedata [0] = 1000;
String contentType =
"application/x-java-serialized-object";
response.setContentType(contentType);
ObjectOutputStream out =
new ObjectOutputStream(response.getOutputStream());
while (true) {
try {
out.writeObject(somedata );
System.out.println("Sent " + somedata [0]);
somedata [0]++;
} catch(Exception ie) {}
out.flush();
Thread.yield();
out.close(); // unreachable if while loop in place
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
Applet side code:
* <P>
* Taken from Core Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
* � 2000 Marty Hall; may be freely used or adapted.
public class testStream implements Runnable {
private boolean isDone = false;
private URL dataURL;
public testStream(String urlSuffix, URL currentPage) {
try {
// Only the URL suffix need be supplied, since
// the rest of the URL is derived from the current page.
String protocol = currentPage.getProtocol();
String host = currentPage.getHost();
int port = currentPage.getPort();
dataURL = new URL(protocol, host, port, urlSuffix);
Thread imageRetriever = new Thread(this);
imageRetriever.start();
} catch(MalformedURLException mfe) {
System.err.println("Bad URL");
isDone = true;
public void run() {
try {
retrieveImage();
} catch(IOException ioe) {
isDone = true; // will never get hit
public boolean isDone() { // meaningless now with infinite loop
return(isDone);
private void retrieveImage() throws IOException {
URLConnection connection = dataURL.openConnection();
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDefaultUseCaches (false);
connection.setRequestProperty("Content-Type", "application/x-java-serialized-object");
ObjectInputStream in = null;
try {
in = new ObjectInputStream(connection.getInputStream());
} catch (Exception pe) { System.err.println(pe); }
while (true) {
// loop forever requesting data
try {
// The return type of readObject is Object, so
// I need a typecast to the actual type.
int[] someData = (int[]) in.readObject();
System.err.println(someData[0]);
} catch(ClassNotFoundException cnfe) {
System.err.println("received NULL");
Thread.yield();

try this: move out.flush() upwards directly after the out.writeObject().
robert

Similar Messages

  • Sending an object from client to server always on button press

    What I need is to send an object from client to server but I need to make server wait until another object is sent. What I have is the JFrame where you put the wanted name and surname, then you create a User object with these details and on button press you send this object to the server. I just can't hold the connection because when I send the first object, server doesn't wait for another button click and throws EOFexception. Creating the while loop isn't helpfull as well because it keeps sending the same object again and again. The code is here
    public class ClientFrame extends JFrame {
        private JButton btnSend;
        private JTextField txfName;
        private JTextField txfSurname;
        public ClientFrame() {
            this.setTitle(".. ");
            Container con = this.getContentPane();
            con.setLayout(new BorderLayout());
            txfName = new JTextField("name");
            txfSurname = new JTextField("surname");
            btnSend = new JButton(new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    SSLSocketFactory f =
                            (SSLSocketFactory) SSLSocketFactory.getDefault();
                    try {
                        SSLSocket c =
                                (SSLSocket) f.createSocket("localhost", 8888);
                        c.startHandshake();
                        OutputStream os = c.getOutputStream();
                        ObjectOutputStream oos = new ObjectOutputStream(os);
                        InputStream is = c.getInputStream();
                        ObjectInputStream ois = new ObjectInputStream(is);
                        boolean done = false;
                        while (!done) {
                            String first = txfName.getText();
                            String last = txfSurname.getText();
                            User u = new User();
                            u.setFirstName(first);
                            u.setLastName(last);
                            oos.reset();
                            oos.writeObject(u);
                            String str = (String) ois.readObject();
                            if (str.equals("rcvdOK")) {
                                System.out.println("received on the server side");
                            } else if (str.equals("ERROR")) {
                                System.out.println("ERROR");
                        //oos.writeObject(confirmString);
                        oos.close();
                        os.close();
                        c.close();
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(ClientFrame.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
                        System.err.println(ex.toString());
            btnSend.setText("send object");
            con.add(btnSend, BorderLayout.PAGE_START);
            con.add(txfName, BorderLayout.CENTER);
            con.add(txfSurname, BorderLayout.PAGE_END);
            this.pack();
            setSize(200, 150);
            setVisible(true);
    public class TestServer {
        public static void main(String[] args) {
            try {
                KeyStore ks = KeyStore.getInstance("JKS");
                ks.load(new FileInputStream(ksName), ksPass);
                KeyManagerFactory kmf =
                        KeyManagerFactory.getInstance("SunX509");
                kmf.init(ks, ctPass);
                SSLContext sc = SSLContext.getInstance("TLS");
                sc.init(kmf.getKeyManagers(), null, null);
                SSLServerSocketFactory ssf = sc.getServerSocketFactory();
                SSLServerSocket s = (SSLServerSocket) ssf.createServerSocket(8888);
                printServerSocketInfo(s);
                SSLSocket c = (SSLSocket) s.accept();
                InputStream is = c.getInputStream();
                ObjectInputStream ois = new ObjectInputStream(is);
                OutputStream os = c.getOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(os);
                boolean done = false;
                User u;
                  while(!done){
                    u = (User) ois.readObject();
                    String confirmString = "rcvdOK";
                    String errorString = "ERROR";
                    if (u != null) {
                        System.out.println(u.getFirstName() + " " + u.getLastName());
                        oos.writeObject(confirmString);
                    } else if (u == null) {
                        oos.writeObject(errorString);
                is.close();
                s.close();
                c.close();
            } catch (Exception e) {
                    System.err.println(e.toString());
    }Thanks for any help, btw this doesnt need to be via ssl, the problem would be the same using only http. Please anyone help me:)
    Edited by: Vencicek on 7.5.2012 2:19
    Edited by: EJP on 7/05/2012 19:53
    Edited by: Vencicek on 7.5.2012 3:36

    Current code fails because it's sending still the same entity again(using while loop)No it's not. You are creating a new User object every time around the loop.
    which makes the system freezeWhich means that you are executing network code in the event thread. Don't do that, use a separate thread. At the moment you're doing all that sending inside the constructor for ClientFrame which is an even worse idea: you can never get out of there to the rest of your client program. This is a program design problem, not a networking problem.
    and doesn't allow me to set new parameters of the new entityI do not understand.
    I need to find a way to keep Server running even when the client doesn't send any data and wait until the client doesnt press the send button again to read a new object.That's exactly what happens. readObject() blocks until data is received.

  • How to continue to read Object from a file?

    At some program I write an object into a file. This program will be called again and again so that there are many objects which are saved to that file. And I write another program to read object from this file. I can read the first object but can not read the second. However if I delete the object in that file (using editplus, by manually) I can read the second. Because now the second object is the first object. (Delete first object).
    The exception when I read the second object is below:
    java.io.StreamCorruptedException: Type code out of range, is -84
         at java.io.ObjectInputStream.peekCode(ObjectInputStream.java:1607)
         at java.io.ObjectInputStream.refill(ObjectInputStream.java:1735)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:319)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:272)
         at LogParser.main(LogParser.java:42)
    Exception in thread "main" The read object from file program is below:
         public static void main(String[] args) throws Exception {
            FileInputStream fis = new FileInputStream(path + File.separator + "ErrorApp21config2.log");
            ObjectInputStream ois = new ObjectInputStream(fis);
            ErrorLog errorLog = (ErrorLog)ois.readObject();
            System.out.println(errorLog.getErrorDate());
            FIFData fifData = (FIFData)errorLog.getErrorDescription();
            CommRegistration commRegistration = (CommRegistration)
                                     fifData.getDataObject(FIFData.REGISTRATION_DATA);
            String ic = commRegistration.getPatient().getPatExtID();
            System.out.println(ic);
            CommQueue commQueue = (CommQueue) fifData.getDataObject(FIFData.QMS_DATA);
            String location = commQueue.getLocation();
            System.out.println(location);
            ois.readObject();  //will throw above exception
            fis.close();
         }Can anyone tell me how to continue to read object? Or I should do some special things when I write object into file?

    Thanks Jos.
    Perhaps you are correct.
    There are some code in a SessionBean to log an object. Write file code is below.
         private void logPreRegError(
              byte[] strOldFifData,
            byte[] strNewFifData,
              String requestID)
              throws TTSHException {
              if (requestID.equals(RequestConstants.ADMIT_PATIENT)){
                String runtimeProp = System.getProperty("runtimeproppath");
                FileOutputStream fos = null;
                   try {
                        fos = new FileOutputStream(
                            runtimeProp + File.separator + "Error.log", true);
                    BufferedOutputStream bos = new BufferedOutputStream(fos);
                    bos.write(strOldFifData);
                    bos.write(strNewFifData);
                    bos.flush();
                   } catch (FileNotFoundException e) {
                        log(e);
                   } catch (IOException e) {
                    log(e);
                   } finally{
                    if (fos != null){
                             try {
                                  fos.close();
                             } catch (IOException e1) {
                                  log(e1);
         }strOldFifData and strNewFifData are the byte[] of an object. Below is the code to convert object to byte[].
         private byte[] getErrorData(FIFData fifData, boolean beforeException, String requestID) {
            ErrorLog errorLog = new ErrorLog();
            errorLog.setErrorDate(new Date());
            errorLog.setErrorDescription(fifData);
            errorLog.setErrorModule("Pre Reg");
            if (beforeException){
                errorLog.setErrorSummary("RequestID = " + requestID +" Before Exception");
            }else{
                errorLog.setErrorSummary("RequestID = " + requestID +" After Exception");
              ByteArrayOutputStream baos = null;
              ObjectOutputStream oos = null;
              byte[] bytErrorLog = null;
              try {
                  baos = new ByteArrayOutputStream();
                   oos = new ObjectOutputStream(baos);
                  oos.writeObject(errorLog);
                  oos.flush();
                  bytErrorLog = baos.toByteArray();
              } catch (IOException e) {
                   log(e);
              } finally {
                if (baos != null){
                        try {
                             baos.close();
                        } catch (IOException e1) {
                             log(e1);
              return bytErrorLog;
         }I have two questions. First is currently I have got the log file generated by above code. Is there any way to continue to read object from log file?
    If can't, the second question is how to write object to file in such suitation (SessionBean) so that I can continue to read object in the future?

  • How to send multiple objects from Client to Server

    Hi
    I have a simple Client - Server architecture. I am trying to send 5 objects from Client to the Server which the server would operate on.
    In the past I've used PrintWriter to pass Strings from Client to Server but now when I am dealing with multiple Objects and PrintWriter not allowing sending of Arrays or ArrayList, how can I send these from the Client to the Server? What would be a good writer to use for this purpose?
    Thanks!

    Thanks, I am looking into ObjectOutputStream but from the API it appears I can only send 1 object at a time. I need to send 5 objects per transaction and then send the next group of 5 objects for another transaction.
    Could you clarify some more on how to put these objects together as a single Object perhaps?
    Thanks

  • How to send multiple objects from appleto to servlet and vice versa

    how can i send multiple objects(ArrayLists and String) from servlet to applet and applet to servlet?

    Use an HTTPUrlConnection from the Applet to the Servlet to send data to the server, or request information from the servlet. To actually transfer the objects you will have to use a serialized version of the objects, almost always by wrapping the streams generated via the UrlConnection in ObjectOutputStream and ObjectInputStreams.

  • Help!!! Sending serialized object to another server/servlet

    I am trying to simply send a serialized bean to a servlet on another server. I have lot's of examples of doing this as a stream and recieving back a stream to output, trouble is, I want to do this as a means of communicating the state of a process from one application kicking off the process on the new application. So when the page is returned, I need to be located on the new server. Here is the stream code I'm using:
    String strUrl = "http://www.myurl.net";
    try {
         URL url = new URL(strUrl);
         HttpMessage msg = new HttpMessage(url);
         BufferedReader in;
         Object beanObj = (Object) myBean;
         MyBean beany = (MyBean) beanObj;
         in = new BufferedReader(new InputStreamReader(msg.sendPostMessage(beany)));
         String inputLine;
         while ((inputLine = in.readLine()) != null) {
         out.println(inputLine + "\n");
         in.close();
    catch(IOException io) {
    out.println("Unable to call the servlet " + io);
    out.close();
    How would I do this if I wanted to send and not come back to the original server?

    Why not create a little daemon to run on Server B (using the Servlet API would make this really easy) that listens for requests from Server A. The Servlet running on Server A would:
    1. Do whatever it needs to do
    2. Open an HttpURLConnection to Server B, use the getOutputStream() method to get a pipe to write serialized data to, couple it with an ObjectOutputStream, and write the session object to it.
    3. Use the sendRedirect() method to redirect the client to Server B.
    Upon receiving a request, the Servlet on Server B would:
    1. Call Servlet.getInputStream() to get the input stream to read objects from.
    2. Couple this with an ObjectInputStream to read objects from.
    3. Read the session object and cast it to the appropriate type.
    4. Stash the session object in a global lookup so it can be retrieved when the client arrives. I don't think the session can be created at this point because the request doesn't originate from the browser.
    Then, finally, the Servlet running on Server B that handles client requests would:
    1. Create a new session
    2. Retrieve the session object from the global data store and stash it in session.
    3. Go on its merry way.
    Hope this was on target and is useful.

  • Problem while sending seriailized  object from applet to servlet

    Hi I m having Object communication between Applet and Servlet.
    I m getting error stack trace as
    java.io.EOFException
         at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
         at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
         at java.io.ObjectInputStream.<init>(Unknown Source)
         at com.chat.client.ObjectClient.write(ObjectClient.java:56)
    at the line
    ObjectInputStream ois = new ObjectInputStream(conn.getInputStream());
    thanks in advance
    Ravi
    the whole code is as follows....
    public Serializable write(Serializable obj) throws IOException,ClassNotFoundException{
              URLConnection conn = serverURL.openConnection();
              conn.setDoOutput(true);
              conn.setDoInput(true);
              conn.setUseCaches(false);
              conn.setRequestProperty("Content-Type", "java-internal/"+obj.getClass().getName());
              conn.connect();
              ObjectOutputStream oos= null;
              try{
              oos = new ObjectOutputStream(
                   conn.getOutputStream());
                        oos.writeObject(obj);
                   catch(Exception ee){
                                       ee.printStackTrace();
                   finally{
                        if(oos!=null){
                             oos.flush();
                             oos.close();
                        return the reponse to the client
                   ObjectInputStream ois=null;
                   try{
    \\this is the line where i m getting the error               
    ois = new ObjectInputStream(conn.getInputStream());
                             return (Serializable)ois.readObject();
                        catch(Exception ee){
                                            System.out.println("Error in Object Client inputstream ");
                                            ee.printStackTrace();
                                            return null;
                        finally{
                             if(ois!=null){
                                  ois.close();

    Did anyone find a fix to this problem. I am having a similiar problem. Sometimes I receive an EOFException and othertimes I don't. When I do receive an EOFException I check for available() in the stream and it appears 0 bytes were sent to the Servlet from the Applet.
    I am always open to produce this problem when I use File->New in IE my applet loads on the new page.. and then I navigate to a JSP sitting on the same application server. When I go to the Applet on the initial page and try to send an object to the server I get an EOFException. No idea!

  • Bizarre ClassCastException when sending serialized objects

    I have two programs communicating with each other over a network using TCP and serialized objects. One of the programs uses an ObjectOutputStream to send the message, and the other uses an ObjectInputStream to receive it. The receiver has a thread that simply loops, receiving and processing messages one at a time.
    Under normal circumstances, this works fine. However, sometimes the sender program has to send more than one message, one right after the other. I guess my assumption was that on the receiving end, they would somehow just "queue up" in the ObjectInputStream and the receiver would be able to read them one at a time. But instead, I get this bizarre ClassCastException whose message talks about members and objects from both messages that were sent. It is as though somehow the two objects received are being mangled together and interpreted somehow as one object. This is strange to me, since I am pretty sure TCP is supposed to guarantee in-order delivery of packets.
    Can I not send multiple messages right after each other through an ObjectOutputStream and have them received in an ObjectInputStream? If not, what would be a good workaround?
    If you need more details, it works like this. I have two classes that look like this:
    class Class1 extends SerializableSuperclass
      Member1 m1;
    class Class2 extends SerializableSuperclass
      Member2 m2;
    }Sender sends an instance of Class1 and then immediately an instance of Class2. Receiver attempts to readObject() from the input stream and gets this exception:
    Exception in thread "Thread-4" java.lang.ClassCastException: cannot assign instance of Class2 to field Class1.m1 of type Member1 in instance Class1
    Isn't that bizarre? Two separate classes, and it is attempting to merge the two in some odd way.
    How do I fix or work around this?
    Thanks

    These classes do not have those methods. They are simply message classes designed to hold data. Do you need to see the methods that call ObjectOutputStream's writeObject() and ObjectInputStream's readObject() methods?
    The serializable superclass is there because it has other stuff including a field identifying the sender. It's basically a base message class.
    Also, the member classes are serializable (serializability isn't the issue anyway; "class cast" is the issue).

  • Problem in Passing JTree object from Servlet pgm to browser

    Dear all:
    Can anybody help to resolve the problem - pass the JTree obejct from servlet (Tomcat) to IE 6.0. The JTree oject alway shows invalid charcter in IE. Following is my coding.
    import java.io.*;
    import java.awt.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.swing.*;
    import java.net.URL;
    import java.sql.*;
    import java.lang.*;
    import java.util.*;
    import javax.swing.tree.*;
    //* Testing1 give it null
    public class SimpleServer extends HttpServlet
    DefaultMutableTreeNode top;
    DefaultMutableTreeNode EX01;
    DefaultMutableTreeNode EX02;
    DefaultMutableTreeNode QB01;
    DefaultMutableTreeNode QB02;
    DefaultMutableTreeNode N2BS;
    DefaultMutableTreeNode N2TS;
    //StringTokenizer st2, st1;
    String query;
    Connection con ;
    Statement statm;
    ResultSet res, backupRes;
    //RowSet res, backupRes;
    TreeSet treeset ;
    String [] tempArray;
    //ServletContext sc ;
    ObjectOutputStream out ;
    DefaultMutableTreeNode temp_node;
         public void doGet(HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException
    resp.setContentType("text/html");
    // resp.setContentType("application/octet-stream");
    System.out.println("create main node") ;
              out = new ObjectOutputStream(resp.getOutputStream());
              out.writeObject(this.set_NodeMain()); //no DB access,
         public void doPost(HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException
         try
         System.out.println("doPost " );
         doGet(req,resp);
              finally
         public DefaultMutableTreeNode set_NodeMain()
    top = new DefaultMutableTreeNode("Tandem");
    EX01 = new DefaultMutableTreeNode("EX01");
    EX02 = new DefaultMutableTreeNode("EX02");
    QB01 = new DefaultMutableTreeNode("QB01");
    QB02 = new DefaultMutableTreeNode("QB02");
    N2BS = new DefaultMutableTreeNode("N2BS");
    N2TS = new DefaultMutableTreeNode("N2TS");
    top.add(EX01);
    top.add(EX02);
    top.add(QB01);
    top.add(QB02);
    top.add(N2BS);
    top.add(N2TS);
    return top;
    }

    JMO - I hate seeing things like this in code:
    Just use whitespace to separate the methods.
    You can't just send a JTree to a browser. A browser has no idea how to render a Java object.
    Put that JTree inside an applet and make it part of a JSP. That'll work.
    MOD

  • Passing Objects from Servlet to Servlet

    Hei,
    how do I pass an object from one servlet to another.. or back to the same again?
    I have my servlet and there I want
    first create an object, then pass that object for processing and manipulating and then pass it for output of the final result..
    How can I send and get the object in a servlet?
    Big thx,
    LoCal

    Hei,
    sorry.. maybe I gave to less informations. In fact it's only one servlet...
    I can't post the original code but something that makes it clear :)
    I wrote the whole project without using Servlet-Technique but normal Java-App. But I designed it so, that I only had to rewrite one class.. and least I thought so.. but now I stuck at this Object-passing problem.
    Sorry.. but I'm pretty new to Servlets
    Thank you very much in advance for your help.
    public class Logger extends HttpServlet {
      private Templates templ = new Templates();
      private Person pers;
      public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        String uname = req.getParameter("user");
        String pwd = req.getParameter("pwd");
        String sts = req.getStatus
        PrintWriter out = res.getWriter();
        switch(sts) {
          case 1: out.println(templ.getXHTMLEditPers(pers));
          break;
          case 2: out.println(templ.getXHTMLViewPers(pers));
          break;
          case 3: out.println(templ.getXHTMLView(pers));
          break;
          default: out.println(tmpl.getXHTMLLogin());
      public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
      doGet(req, res);     
    }

  • Exception sending serialised data from servlet to applet

    Hello,
    I have a servlet that sends periodically a serialised object to an applet, under a http get request. it works fine, but if I force the comunication not waiting too much between requests, I am getting this anoying exception:
    java.io.StreamCorruptedException:EOFException while reading stream header
    This is a piece of code:
    SERVLET--------
    (called within the doGet)
    public void sendSerialisedData(HttpServletResponse response, PlatformData dataToSend)
    ObjectOutputStream outputToApplet;
    try
    outputToApplet = new ObjectOutputStream(response.getOutputStream());
    response.setContentType("application/x-java-serialized-object");
    outputToApplet.writeObject(dataToSend);
    outputToApplet.flush();
    outputToApplet.close();
    catch (IOException e)
    e.printStackTrace();
    APPLET--------
    HttpURLConnection servletConnection = (HttpURLConnection)url.openConnection();
    servletConnection.setDoOutput(false);
    servletConnection.setDoInput(true);
    servletConnection.setRequestMethod("GET");
    servletConnection.setUseCaches(false);
    servletConnection.setDefaultUseCaches(false);
    servletConnection.setRequestProperty("Content-type","application/x-java-serialized-object");
    ObjectInputStream inputToServlet = new ObjectInputStream(servletConnection.getInputStream());
    setTheData( (PlatformData) inputToServlet.readObject());
    inputToServlet.close();
    servletConnection=null;
    The method that receives the refresh petitions in the client is synchronized, that means that I have ensured that no petition will be processed until the method on charge of processing it has finished.
    I have spent 3 days with this problem, but I have not been lucky. Does anyone have an idea of what is happening?
    thank you very much
    carlos
    [email protected]

    the
    communication works fine until you force a more
    frequent communication... Ok.
    I had a similar problem a while back while implementing an applet-servlet pipeline. I remember solving it by writing the objs in byte arrays and sending the byte arrays instead. The only other difference is that I was using POST instead of GET.
    In your servlet :
    // first
    con.setRequestProperty("Content-type","application/octet-stream");
    // method
    private byte[] convertObjectToByteArray( Object obj ) throws IOException
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream( b );
    out.writeObject( obj );
    return b.toByteArray();
    // code
    byte[] b = convertObjectToByteArray( obj );
    ObjectOutputStream out = new ObjectOutputStream( resp.getOutputStream() );
    out.writeObject( b );
    out.close();And in your applet, get the byte array and convert that to objects.:
    // method
    private Object convertByteArrayToObject( byte[] b ) throws Exception
    ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream&#10149;
    ( b ) );
    return in.readObject();
    // code
    ObjectInputStream in = new ObjectInputStream( con.getInputStream() );
    byte[] b = (byte[])in.readObject();
    in.close();
    // then call convertByteArrayToObject( b );If the above does not make a difference, I'm afraid I can't be of further help...

  • How to send an object from one application to another?

    Hi all,
    I have two applications over the same server. The first application needs to send an object to the other application.
    I try to put the object as a session attribute, but in the moment that the second application tries to get the attribute, the attribute doesn't exist.
    Does anybody now how can pass an object from the one application to the other?

    You can also use JMS

  • How to send a message from Servlet to JSP

    Dear all,
    I have JSP, with JavaScript (AJAX). If the user click on the button, the text will be sent to a Servlet parsed by doGet() and the user get a response to his input, without reloading a page.
    How can I send a message to the users (JSP) from Servlet, if he didn't clicked any button and to other visitor of the page also? Is it possible? I think like a chat, the server sends a message to all users who are subscribed.
    I don't know, what should I get from user, maybe session, that I could send him personal or common messages in his textarea. I should also invoke some JavaScript function to update his page. I have met some chats, you don't do nothing and get messages. It is also without a JavaScript timer, which invokes doGet() method. Asynchronous, only when there is a message.
    Please help me with a problem.
    Thanks in advance.

    Hai ,
    You can send any message through response.sendRedirect();
    here is the coding try it
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class SimpleCounter extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    String username="java";
    res.sendRedirect("http://localhost:8080/yourprojectname/jspfile.jsp?username="+username);
    }

  • How to send the values from servlet to jsp

    hi folks,
    I need to send a lot of values from servlet to jsp so that i can display the values in jsp. Any sollution for this. Its very urgent.
    Thanks in advance

    Hi lieo,
    Can u send me the sample code for that.
    Thank q

  • Serialized Objects and Servlets

    I'm having a lot of trouble accessing a serialized object and displaying it in a servlet. I get the following exception:
    java.io.StreamCorruptedException: Type code out of range, is -84
    Can anyone help me out here?

    OK... here's some of the code I'm using...
    public Object readObject()
    throws IOException, ClassNotFoundException
              oin = new ObjectInputStream(fin);
              Object obj = oin.readObject();
              oin.close();
              return obj;
    public void writeObject(Object data)
    throws IOException
              oout = new ObjectOutputStream(fout);
              oout.writeObject(data);
              oout.close();
    Essentially, my servlet creates and instance of an ObjectManager class. This ObjectManager then tries to execute the readObject method above.
    The whole process comes to a grinding halt at this point:
    Object obj = oin.readObject();
    I think this problem has to do with the way that I'm trying to access the file to which I have serialized my object. The problem is that I can't think of any other way to do it. Here's how I am currently referencing the file that holds my serialized object:
    File theFile = new File("Serialized.dat");
    FileInputStream fin = new FileInputStream(theFile);
    I've never attempted anything like this before and I suspect I'm way off in my approach. I really appreciate your willingness to help me out.

Maybe you are looking for

  • Moving iPhotos from one account to another via "Shared" folder

    Every once in awhile, I like to share photos between accounts on the same iMac, so that my wife can use some of the pictures. Lately, if I put them in the "Share" folder on the HD, they come out NOT useable in the other account. They are usually in j

  • Facing Problem while Displaying Russian words using HTP.TableData

    Hi, We are storing russian words in DB.While displaying these words, it is not displaying proerly.we are using "HTP.TableData" to display russian characters in the front end.Please suggest the solution to display russian words proeprly

  • Short dump in BP after upgrade to ECC 6.0

    Hi, We have upgraded system to ECC 6.0 from ECC 5.0 After upgrade system is giving short dump in transaction BP, event tried to navigate on BP screen. Short dump description: A RAISE statement in the program "CL_OS_TRANSACTION=============CP" raised

  • Video list don't work after update to ios 6

    Hi, I have some lists of videos and after upgrade my iphone 4 to IOS 6 they don't work. In iphone that lists come empty. I try made a new one but have same result. The list is empty. On itunes that lists are OK, complete fill in.

  • One way SMS + OTP in Azure MFA server

    Hi, how can i enable one way SMS in Azure MFA on premise? I have Azure MFA server and local active diretcory. I want users to receive a OTP and enter it to the logon page instead of replying to it? how can this be done? and if it is via the SDK, any