Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Applet Servlet Serialized Object

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet that invokes a Twain Device on a Client Machine, the aim of my code is to take photgraphs using a webcam and allow a user to store the image in my database. I have successfully written the applet to handle this and even save the file on the user machine. But I need the Applet to save the image on a DB my server. Can Anyone direct me on how to send a serialised object back to a servlet from my applet.

I would like to send the Image as an output stream to my servlet
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I would like to send the Image..


I don't think there is a Serializable Image class, go for a int[] of pixels maybe. Image objects are all tied up in the graphics capability of a given platform so I don't think they can be serialized.
Bill
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your applet has access to the client file system, which from the sound of it, it does, why not just send it as a serialized instance of java.io.File?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can Anyone direct me on how to send a serialised object back to a servlet from my applet.



Chapter 17 covers this:
http://pdf.coreservlets.com/
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

why not just send it as a serialized instance of java.io.File?


How is an instance of File going to help get the image to the server?

Bill
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never tried with an image but I have, in the past, sent serialized Java objects to the server from an applet via HTTP posts by setting the content type to: "application/x-java-serialized-object".

Since java.io.File implements java.io.Serializable, I would think you could send an image (or any file) that way.


Ola,
The first link I posted only covers sending serialized objects from a servlet to an applet. This one has examples of sending serialized objects in both directions.
http://www-128.ibm.com/developerworks/java/library/j-tunnel/?dwzone=java
[ November 22, 2005: Message edited by: Ben Souther ]
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File objects can be serialized, but they represent just the file descriptor, not the contents. They only have meaning on the originating machine; you can't send them over the wire.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.
So the file would need to be read and the stream sent to the server.

My mistake.
Thanks William, Ulf.
[ November 22, 2005: Message edited by: Ben Souther ]
 
Ola Daniel
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Thanks for all the help. Problem solved. I convert the image to a bytes array in the applet and send it back to my servlet, which then inserts it in the database.

Both links were very verrryy halpful. Thanks Again
[ November 23, 2005: Message edited by: Ola Daniel ]
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic