Servlets-4a

Ronald Schindler

Ranch Hand

Posts: 50

posted 14 years ago

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

Posts: 9080

12

posted 14 years ago

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

Posts: 50

posted 14 years ago

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

Posts: 129

posted 14 years ago

Your general premise is true for an ArrayList that is an instance attribute....

Darryl Failla
Sun Certified Java 2 Programmer

Pauline McNamara

Sheriff

Posts: 4012

6

posted 14 years ago

Excellent tip Darryl. You'll have to wait for Servlets-4b to play with sessions, Ronald.

Ronald Schindler

Ranch Hand

Posts: 50

posted 14 years ago

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

Posts: 129

posted 14 years ago

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.

Darryl Failla
Sun Certified Java 2 Programmer

Michael Matola

whippersnapper
Ranch Hand

Posts: 1836

5

posted 14 years ago

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

Posts: 1211

posted 14 years ago

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

Posts: 6

posted 14 years ago

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

Posts: 4012

6

posted 14 years ago

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.