Hi All,

I appreciate your comments.
And please forgive me my poor English and a lack of my java knowledge.

Let me say in detail.
Basically I am following the article concept in Servlet Central March Issues.
I hava a controll servlet "Manager" , an ancestor transaction class "Transaction"
and many desecndent classes "A" , "B" , "C" . . .

the Transaction class has such a structure

public class Transaction
{
  Hashtable param;    // for request parameter
  Hashtable mydata;   // for my DB data
  String TransID;

  public BBSTransaction (String thisTransID)
  {
    param = new Hashtable();
    mydata = new Hashtable();
    setTransID(thisTransID);
    . . .

   protected synchronized StringBuffer gethtml()
   {
        //. . .
        // Enumeration en = this.mydata.keys();   Implement it at the desecndent 
classes.
         //  while(en.hasMoreElements()) {
         //     . . .
         //  }
         //. . .
        return new StringBuffer();
   }

   protected synchronized void dbwork()
   {
      // this.mydata.put(key,value);  implement it at the desecndent classes.
   }

  . . .
}

And the Manager has such a structure

public class Manager extends HttpServlet
{

public void init(ServletConfig config) throws ServletException
{
  super.init(config);
  }
   . . .
public void doPost (HttpServletRequest req, HttpServletResponse res) throws 
ServletException, IOException
{
   . . .
  StringBuffer html = new StringBuffer();
  HttpSession session = req.getSession(true);
  Class transClass;
  try {

   transClass = (Class.forName(req.getParameter("transaction")));
   session.putValue("Transaction", (Transaction)TransClass.newInstance());
   
((Transaction)session.getValue("Transaction")).setTransID(req.getParameter("transaction"));
   . . .
  ((Transaction)session.getValue("Transaction")).dbwork();
  html.append(((Transaction)session.getValue("Transaction")).gethtml());
  . . .

   }
. . .
}

My problem is , for example When I got some data, "HT",  from DB at the class A, I 
used it and
after load / reload class B or C for next work I would like to use the old Data, HT, 
instead of recall DB.
In order to save this HT in the session objects, I added the code in the Transaction 
Class like
public Hashtable getHT()
{
    return this.mydata;
}
and added the code in the Manager Class like
((Transaction)session.getValue("Transaction")).mydata.put(key, 
((Transaction)session.getValue("Transaction")).getHT()));

But I failed because  the getHT() method return this times data not old Data when load 
another Class.

I'm not sure it is basic and silly question, but I hope you can understand my problem 
clearly

Thanks for your comment and
I appreciate if you correct my problem.
Any codelet or comment appreciates.

Thanks again.

youngho

-----¿øº» ¸Þ½ÃÁö-----
º¸³½ »ç¶÷: Ted Neward <[EMAIL PROTECTED]>
¹Þ´Â »ç¶÷: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
³¯Â¥: 1999³â 7¿ù 29ÀÏ ¸ñ¿äÀÏ ¿ÀÀü 10:50
Á¦¸ñ: Re: How can I reuse a data at the dynamic class roading servlet


>There may be a miscommunication here.
>
>youngho, when a Class is loaded for the first time into a JVM, using
>Class.forName or because another class requires it when that other class is
>loaded, the Class is loaded, resolved, and associated forever with the
>ClassLoader instance that loaded it. If for some reason that ClassLoader
>should "go away", then the Class will need to be reloaded, and any data
>stored with that Class is lost forever.
>
>However, so long as that ClassLoader remains in place, subsequent calls to
>Class.forName() will reuse the already-loaded class and NOT re-load the
>Class from disk. Thus, when you say that "But my problem is whenever the
>Class reload , the HT becomes null !. >> I would like to know how can I
>reuse a data even after the class reload at >the dynamic class roading
>method. "[sic], I'm not entirely sure what you're intending. I believe Andy
>has it right, that you need to keep the *instance* of the class around
>longer in order to reuse it between invocations, but that has nothing to do
>with the *class* being reloaded all the time--the instance could not exist
>had the class not been loaded first.
>
>Can you clarify or post some code to demonstrate what you're trying to do?
>
>Ted Neward
>Patterns/C++/Java/CORBA/EJB/COM-DCOM spoken here
>http://www.javageeks.com/~tneward
> "I don't even speak for myself; my wife won't let me." --Me

___________________________________________________________________________
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