• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Passing Object from Applet to Servlet

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.setDoInput(true);
con.setDoOutput(true);
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++)
out.writeObject(myObjs[x]);


out.flush();
out.close();

return new ObjectInputStream(con.getInputStream());
}

Good Luck.
Todd
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic