File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Applet Servlet Serialized Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Applet Servlet Serialized Object" Watch "Applet Servlet Serialized Object" New topic
Author

Applet Servlet Serialized Object

Ola Daniel
Ranch Hand

Joined: Jul 27, 2005
Posts: 105
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


SCJP 1.4, SCWCD 1.4
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
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

Joined: Dec 11, 2004
Posts: 13410

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?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Mar 22, 2000
Posts: 12792
    
    5
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

Joined: Dec 11, 2004
Posts: 13410

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
Marshal

Joined: Mar 22, 2005
Posts: 42050
    
  64
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.


Ping & DNS - my free Android networking tools app
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jul 27, 2005
Posts: 105
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 ]
 
GeeCON Prague 2014
 
subject: Applet Servlet Serialized Object