It's not a secret anymore!*
The moose likes Cattle Drive and the fly likes Servlets-4a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Servlets-4a" Watch "Servlets-4a" New topic
Author

Servlets-4a

Ronald Schindler
Ranch Hand

Joined: Jul 11, 2000
Posts: 50
Hoping someone can provide some further direction. I have it pretty clear in my head how to do the general assignment (at least I think so) except for one part, how do we maintain the list of videos in memory. I could write them out to a file but that seems to go against what is being asked for and jdbc is yet to come.
Therefore I have to assume that the arrayList is held in memory somehow but one I leave the servlet page or write the video to the arrayList I lose the reference to it. I'm assuming this is where the mystery file comes in but I'm not sure.
Any help would be appreciated.
Thanks.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Originally posted by Ronald Schindler:
... how do we maintain the list of videos in memory. I could write them out to a file but that seems to go against what is being asked for and jdbc is yet to come.


Writing to a file is not maintaining the ArrayList in memory, it is persisting it. The same applies to jdbc. You will be persisting the list in a database. You don't need to persist the ArrayList for Servlets-4a.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Ronald Schindler
Ranch Hand

Joined: Jul 11, 2000
Posts: 50
Marilyn,
That's exactly what I was thinking. But if the list is to persist in memory then it seems that it needs to have a reference kept to it at all times so that gc doesn't pick it up. When I leave a servlet and go to an html page, I would lose the reference and therefore the list. I was thinking about turning the html pages into servlets similar to the last assignment but wasn't sure if one, this was acceptable and two, if this would actually work. My assumption at this point is that the mystery file is supposed to maintain session somehow but I'm still thinking this through.
Any other commentary is welcome.
Thanks.
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 128
Your general premise is true for an ArrayList that is an instance attribute....


Darryl Failla
Sun Certified Java 2 Programmer
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Excellent tip Darryl.
You'll have to wait for Servlets-4b to play with sessions, Ronald.
Ronald Schindler
Ranch Hand

Joined: Jul 11, 2000
Posts: 50
Thanks for the instance comment that helped.
Here's where I'm at now. I am successfully calling the AddVideoServlet and adding the video. I get a true on add and have a count increase when I add. So far so good.
The ListVideoServlet however knows nothing about what was added. If I check to see what was added by AddVideoServlet, I get back a big fat 0 for the number of videos, which was my concern. ListVideoServlet has no knowledge of where the videos were added. How should it know where to look for what has been added into memory? My thoughts are that these objects need to be aware of each other but I'm not sure how to make that happen when they don't talk to each other.
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 128
When I get these types of problems, I usually try to hard-code some data into my data field (a static block in the class will perform operations upon class loading). Then try to perform a read. If you can read the data, your problem is with improper writing. If you can't read the data, then it's improper reading.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1746
    
    2
Originally posted by Ronald Schindler:
My thoughts are that these objects need to be aware of each other but I'm not sure how to make that happen when they don't talk to each other.

Well that's the fun of the assignment!
There are a couple of different ways to do this.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
I can't remember how I arrived at a solution to this one, but it seems the clues were in the assignment itself.
Now, since these two servlets can't talk to each other, it seems to me that they will have to communicate through a third party............
Albert Schweitzer
Greenhorn

Joined: Oct 25, 2002
Posts: 6
Hi Folks,
is it necessary to use a "mystery.java"-file for this assignement? I did it without that and now I'm afraid the solution is not very proper!?


Kommt Zeit, kommt Bart!
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
There's usually more than one way to get a solution working for any of the assignments. (Anyone who's gone through nitpicking can attest to that!) Whether or not your solution is "proper" for the Cattle Drive, well, there's only one way to find that out - have to send it in to be nitpicked.
Submitted solutions certainly don't need to "match" the instructor's solution exactly, but I suspect for this one you would be expected to come up with a "mystery file". The instructor's solution for Servlets 4a has a particular structure that highlights inheritance really nicely.
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
... and will be even more visible in JDBC 4! using servlet stuff.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets-4a
 
Similar Threads
arrayList.clear() VERSUS arrayList = new ArrayList()
replacing content in a file
data access class
resultset processing gives java.lang.OutOfMemoryError
Memory Mgt: Giving memory from ArrayList back to VM?