• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem Sending and Receiving Objects from Servlet  RSS feed

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!