Hi Carl,
I am also looking for same thing. I have written a bean for counter. I want
to serialise this bean  to a file so that on server restart i should be able
to get the last  count . Currently  I am explicitily writing it in file
using stream . I want to use object serialisation.
I have ' implements serialisable' but yet not clear when and what method
will be called when server is being stopped.

pl. shed some light on it.

with regards,
Avinash


-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Carl
Woermann
Sent: Wednesday, February 05, 2003 10:33 PM
To: [EMAIL PROTECTED]
Subject: Using serialization to re-/store state:
UnknownServiceException: protocol doesn't support output:


Hi all..

I'm using jsp & tomcat4.
The application collects user data.
I have a bean that contains all relevant data.
I am using serializtion to make the data persistant.
In order to restore the state of the bean I use:

<% URL resourceUrl =
application.getResource("/resource/SerializedBean.ser"); %>

// returns a valid url: jndi:/localhost/resource/MemberBean.ser

<jsp:useBean  id="registrationBean" scope="application"
type="Package.class" beanName="Package.SerializedBean" >
<%
 // the saved version is restored if there is no instance of this bean.
 boolean bool = registrationBean.restoreState(registrationBean,
resourceUrl);
 out.print("restored state: " + bool); //for debugging purposes..
%>
</jsp:useBean>

When saving the state with:

registrationBean.saveState(resourceUrl);

I get the following exception report:

Starting service Tomcat-Netbeans
Apache Tomcat/4.0.4
restoring state : jndi:/localhost/resource/MemberBean.ser
saving state to : jndi:/localhost/resource/MemberBean.ser
can do output: true */ SEE METHOD CALL BELOW /*
java.net.UnknownServiceException: protocol doesn't support output
        at java.net.URLConnection.getOutputStream(URLConnection.java:679)
                etc...

the code of the save state method is below:

public synchronized void saveState(URL url){
        this.url = url;
        try {
        URLConnection uConn = url.openConnection();
        uConn.setDoOutput(true);
        if (debug)
            { System.out.println("can do output: " + uConn.getDoOutput()); }

                OutputStream out = uConn.getOutputStream();
            ObjectOutputStream s = new ObjectOutputStream(out);
            s.writeObject(this);
            s.flush();
            s.close();
         uConn.setDoOutput(false);
        }
        catch(FileNotFoundException fnfex){ fnfex.printStackTrace(); }
        catch(IOException ioe){ ioe.printStackTrace(); }
    }

Can anybody shed some light on this problem?
What other means are availiable to make beans persistant within a Servlet
Container?

Any suggestions are greatly appreciated.

Thank you
CARL WOERMANN




__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

___________________________________________________________________________
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