File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Passing Object from Applet to Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing Object from Applet to Servlet" Watch "Passing Object from Applet to Servlet" New topic

Passing Object from Applet to Servlet

Ashish Thakur

Joined: Mar 18, 2000
Posts: 22
I am trying to send myObject(extending Object implements Serialize) from applet to Servlet using the UrlConnection class. But am unable to do so.
I am using the JavaWebServer2.0 evaluation version. Is it that the server does not support this facility in this eval. copy , Or do i have to do Something else during sending and reading the myObject using the ObjectInput/OutputStream
Any help will be much appreciated.
Thanks for reading this.
Java Rules.
Ashish T.
Todd Bush

Joined: Mar 06, 2000
Posts: 14
Hopefully this will help you. This is how I am doing it....
This is called to add a sourceName and sourceType to the db. A boolean is returned weither the action was successful or not. The code Integer indicates to the Servlet which function to use. My servlet houses many functions. I place a call to postObject to do the actual transfer (code at the bottom)
public Boolean addSource(String SourceName, String SourceType) throws Exception {
servlet = new URL(webBase,"servlet/AZUniversalServlet");
Integer code = new Integer(5);
Serializable objs[] = { code, SourceName, SourceType };
in = postObjects(servlet, objs);
Boolean result = (Boolean)in.readObject();
return result;

private ObjectInputStream postObjects(URL myServlet, Serializable myObjs[])throws Exception {
URLConnection con = servlet.openConnection();
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
int numObjects = myObjs.length;
for(int x= 0; x<numObjects; x++)


return new ObjectInputStream(con.getInputStream());

Good Luck.
I agree. Here's the link:
subject: Passing Object from Applet to Servlet
It's not a secret anymore!