Forums Register Login

Problem Sending and Receiving Objects from Servlet

+Pie Number of slices to send: Send
Hi folks!

I have an Java Application that communicates with a servlet by the ObjectInput and ObjectOutput Streams.
I made it work to send and receive data.
The problem is that when I have to send an object to servlet and to receive an object from servlet, my application does two diferent requests to this servlet.
It follows the code:
{
// send data to the servlet
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);
oos.writeObject(obj);
oos.flush();

// receive data from servlet
InputStream instr = con.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
Object result = inputFromServlet.readObject();
inputFromServlet.close();

oos.close();
instr.close();
return result;
}

How can I change it to make only one request to servlet, sending and receiving an object from it.

Thanks!
Jo�o Cunha
+Pie Number of slices to send: Send
Do you mean that you want to write the object and then read the object you just wrote? Why would you want to do that?

Anyway, there is no way that I know to do that all at once. OutputStreams write and InputStreams read. That's the way it is. There is no stream that does both that I'm aware of.
permaculture is giving a gift to your future self. After reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 530 times.
Similar Threads
servlet/applet communication problem
applet servlet communication
sending image file from applet to servlet
applet servlet communication
sending image file from applet to servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:52:57.