Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets-4a

 
Ronald Schindler
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ronald Schindler
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your general premise is true for an ArrayList that is an instance attribute....
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent tip Darryl.
You'll have to wait for Servlets-4b to play with sessions, Ronald.
 
Ronald Schindler
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1821
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!?
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and will be even more visible in JDBC 4! using servlet stuff.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic