Jiger Patel wrote:
>
> I am working on Applet-Servlet Communication & tried to send the Session
> object to the Client Applet using writeObject of ObjectOutputStream but it
> seems to give some FileNotFoundException in the Client Applet although no
> exception is raised in the servlet. I found out that HttpSession is not
> Serializable so you cannot transfer it.
> Is it true?. How can I send an entire Session object to the Client so that
> the client can get the Values put by the servlet in it.
> or access some session values like LastAccessedtime etc.
Even though its possible, you really don't want to do this. When the session
object is taken out of the context of the server, it may lose meaning. The
session object is designed to work within a server, not passed around all over
the net. The fact that you want to do something to the session object that the
session was not designed for suggests you may not be using the best solution for
your requirements. The session is meant to store information that the server
needs to create a persistent state for a client; if you need to put things into
the session object it should be done by the server or servlet.
There's another reason why sessions are not serializable: sessions can hold
objects and the session implementer has no idea whether the objects that will be
stored in the session are serializable or not.
After having said all that, if you really, really, really, want to persist in
this course, here are some suggestions:
Have the servlet implement a get/set service for the applet to call. If the
applet needs to set or get a value, it calls the servlet with the name/value to
set or the name to get. If the applet needs to store an object, you will have to
serialize the object somehow for sending or receiving.
Have the applet maintain its own session-like storage for itself.
If the name/value pairs are just strings, the servlet can send all the
name/value strings in one long string object. The applet parses through the
string for values it needs; it appends a name/value pair to the string and sends
the string back to the servlet to add a value.
Put the name/value pairs in some other collection object (Vector, Hashtable,
etc.) and serialize that. As mentioned above, you can only do this if all the
objects in the session are serializable. If the servlet or server put an object
in the session that is not serializable, then you can't send that object.
K Mukhar
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html