File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet Servlet Serialized Object

 
Ola Daniel
Ranch Hand
Posts: 105
  • 0
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • 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 Redhat VI Editor
  • 0
  • 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
Rancher
Posts: 13048
6
  • 0
  • 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 Redhat VI Editor
  • 0
  • 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 ]
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • 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 Redhat VI Editor
  • 0
  • 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
  • 0
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic