Are you certain you're retrieving the HT data by the same name each time? It
looks like you're putting HT up into the session using the name passed in
for the transaction type--the first time as "A", the second time as "B", and
so on. Try putting it up under the string constant "HT" instead, and it
should be there each time.
If you put something into a Hashtable under the key "A", you will *NEVER* be
able to get it back under the key "B". Ever.
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
-----Original Message-----
From: Youngho Cho <[EMAIL PROTECTED]>
To: Ted Neward <[EMAIL PROTECTED]>
Date: Monday, July 26, 1999 8:59 PM
Subject: Re: Re: How can I reuse a data at the dynamic class roading servlet
>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
>>
>>-----Original Message-----
>>From: Andy Bailey <[EMAIL PROTECTED]>
>>To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>>Date: Monday, July 26, 1999 10:05 AM
>>Subject: Re: How can I reuse a data at the dynamic class roading servlet
>>
>>
>>>> Hi,
>>>> I have a question.
>>>> I use a dynamic class roading mathod using Class.forName method in my
>>>controll servlet.
>>>> ( there is only one control servlet and many transaction classes)
>>>> At the one stage, I got a client requested parameter through
getParameter
>>>method ,
>>>> pass the parameter to my DB , received some data ( Let's call HT )
from
>>>DB and return back a part of data to
>>>> the client. Ath the next stage ( reload a new class ) , if a client
>>>request a more detail data
>>>> then I would like to reuse HT.
>>>> 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.
>>>> Any codelet or suggestions appreciates.
>>>>
>>>> Thanks in advance.
>>>>
>>>> youngho
>>>>
>>>The class reload is not the problem here.
>>>
>>>Your data (HT) will be lost between requests unless you can store it in
the
>>>session object.
>>>
>>>HT needs to be Serializable for this to work.
>>>
>>>You can then do session.putValue("somekey", HT);
>>>to store it.
>>>
>>>HTClass HT = (HTClass)session.getValue("somekey");
>>>
>>>gets it back for you.
>>>
>>>Hope that helps
>>>
>>>Andy Bailey
>>>
>>>_________________________________________________________________________
__
>>>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