This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing Object from Applet to Servlet  RSS feed

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