sending java object from applet to a servlet container

K

killjoy

Hi,

I've been developing a web application which makes use of java applet
too. What I need to do is to send a serialized java object from applet
to a servlet container, get the necessary data from this object to be
used in a jsp. Imagine a situation that a user click on a button on
the applet, and a report will be generated in a jsp. Is it possible?
All your help is highly apreciated ;-))

Thanks
 
S

Silvio Bierman

killjoy said:
Hi,

I've been developing a web application which makes use of java applet
too. What I need to do is to send a serialized java object from applet
to a servlet container, get the necessary data from this object to be
used in a jsp. Imagine a situation that a user click on a button on
the applet, and a report will be generated in a jsp. Is it possible?
All your help is highly apreciated ;-))

Thanks

This is quite easy to achieve using HTTP. It goes something like this:

String serverUrl = "http://server.com:8080/server.jsp";
Object requestObject = new SomeRequestType();
URL servlet = new URL(serverUrl);
HttpURLConnection con = (HttpURLConnection)servlet.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
out.writeObject(requestObject);
out.close();
ObjectInputStream in = new ObjectInputStream(con.getInputStream());
SomeResponseType response = (SomeResponseType)in.readObject();
in.close();

The HttpURLConnection can be used to set HTTP headers etc. If
requests/responses are very big you might consider using gzip streams to
wrap the bare streams in. It is probably also best to use buffered streams.

Regards,

Silvio Bierman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top