Try using the setAttribute() and getAttribute() methods available on the
ServletContext or HttpSession objects.  As long as the object you store as
an attribute of the servlet context or user session is serializable, this is
a great way to share data between a synchronous servlet-to-servlet process
where one servlet delegates control to another, or asynchronous, individual
servlet processes where objects need to be persisted for longer than the
request/response cycle.

These are very easy to use and only require you to cast the getAttribute()
return value back to the type you need, since it returns a generic Object
when deserialized.


e.g.

SomeObject sObject = new sObject(...);
httpSession.setAttribute("someObject", sObject);

...

SomeObject persistedObject = (SomeObject)
httpSession.getAttribute("someObject");


-drumshamen

| -----Original Message-----
| From: A mailing list for discussion about Sun Microsystem's Java Servlet
| API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of G S
| Sundar
| Sent: Wednesday, July 04, 2001 4:18 AM
| To: [EMAIL PROTECTED]
| Subject: Re: How to share a common object between two servelts?
|
|
| Hello Manish/All,
| How do i pass/use the serialized the object between  the
| servlets. I used the
| object serialization in Applet - RMI i don't know how to use this with
| Servlets. Can you throw some more light in this area.
| Sample code will be more helpful to me.
|
| Regards
| G S Sundaram
|
|
| Manish Bhatnagar wrote:
|
| > Object serialisation may solve your problem
| >
| > -----Original Message-----
| > From: A mailing list for discussion about Sun Microsystem's Java Servlet
| > API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of G S
| > Sundar
| > Sent: Wednesday, July 04, 2001 1:31 PM
| > To: [EMAIL PROTECTED]
| > Subject: How to share a common object between two servelts?
| >
| > Hello All,
| > I've two servlets running in different ports. How do share a common
| > object between these two servelts. Once the
| > values updated by Servlet-1 i would like to use the LATEST values (with
| > out accessing the DB) from Servlet-2.
| > Or
| > Can i get the Servlet Context of Servlet-1 from Servlet-2.
| >
| > Thanx in advance!!!
| >
| > Regards
| > G S Sundaram
| >
| >
| __________________________________________________________________
| _________
| > 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
| >
| >
| __________________________________________________________________
| _________
| > 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
|
| __________________________________________________________________
| _________
| 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

___________________________________________________________________________
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

Reply via email to