I'm making a Servlet application using the a MVC-like implementation, however I'm slightly confused on how I should delegate concurrent modification of the state of the Model object?

I intend to use a database to hold information from a given session for a particular individual (the data will be retrieved based on a username and password).

It doesn't seem possible or practical to store a Thread in the Model object, so that's really not an option.

I do want to respect the MVC implementation such that the View is dependent on the Model object and the Controller changes the state of the Model.

The question is, how do I make the View update when the Model changes state? The View is going to be a JSP that has action-value attributes. Since the View is really just a page (and not an object), how do I tell the page to refresh based on the new information? Must I rely on the Controller to do so?

I understand that Servlets run in a multi-threaded server environment, though I'm not sure how this is exercised upon the model. It seems like a waste to force the page to be refreshed every millisecond (and potentially costly to the client), though I don't understand any other way for the type of program I wish to write.

To be slightly more specific, I'm planning on remaking Snake-it in a Servlet environment as a practice program for JSP and Servlet programming. The information will be stored in a database for a given session.

Any feedback would be appreciated. Thank you.

-Alex

Though this doesn't quite answer my question, a good amount of information provided by peter_budo was found here.

I need to point out, that the post is not finished yet. I will get rid of snippets (need to gather some more info), improve DB, implement PreparedStatements and provide some additional info on some points. I hope to finalize it in next two weeks and get it approved

Most of the information is pretty straightforward in terms of Model 2.

However, I'm still struggling to understand how to implement my design for this project...

I don't know if what I need is an Active Server Page, or a Page that, somehow, listens for changes in the database and refreshes accordingly... or simply (if possible) have a thread active that will (somehow) refresh the page whenever a state change in the Model is visible.

I'm completely at the mercy of learning Servlets more thoroughly, which I don't have a problem with. I'd just like to know if what I'm attempting to do is easy, or hard, from an experienced Servlet/JSP-user's perspective.

-Alex

Edit: Will I need to implement Java-code in the View instead (for example, a Panel or some kind of Swing component)? I don't know of what's allowed in a HTML, but I'd assume that Swing components are ok.

I hope these questions don't seem stupid!

If an elaboration is needed, the intent is to make the Snaker animated in the View for the Model 2 scenario. Unfortunately this means that the Model must be updated constantly along with the View.

I want to hold true to the MVC pattern, though I'm not sure if I can do it in this way. The only other option is to allow the Controller to have a thread to constantly change the state of the model so the view can reflect the changes.

This article has been dead for over six months. Start a new discussion instead.