File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Web-State Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Web-State Pattern" Watch "Web-State Pattern" New topic

Web-State Pattern

Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
I've been asked to look into the Web-State Pattern for some JSP / servlet work I'm about to start ... is this the same as the MVC pattern?
from what I understand both make use of JSPs (view) JavaBeans & Servlets (model & controller).
Has anyone done any development using this pattern? How does it essentially work?

Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
It may be related to the "State" pattern in GoF (always worth a re-read for any patter question). In the State pattern, the state of a process is represented by an instance of a class which implements an interface (or extends a particular base class). To change state, simply replace the state object with another object. The code using the state object neither knows or cares which state it is in.
For a web-specific use you might have a single JSP in which a named bean represents the state. Either in the JSP or in one or more associated servlets, you could make sure that the correct bean is in the session ready for the JSP each tim eit is called.
Does this make sense?

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Akin Kaldiroglu

Joined: Oct 10, 2000
Posts: 9
MVC-State Pattern is actually is the combination of MVC and State patterns. Main idea is based on a servlet that acts like a controller to get the requests from the web clients and delegate it to the model. So far it is pure MVC. The effect of State pattern comes when your model have different states and all these states are represented with different JSP. So the Context in the State pattern of GOF corresponds to the servlet itself. It sends the requests to State interface and depending upon the state which your state-dependent object is the servlet redirect the response to a different JSP, which is specificaly designed for that state. In this scenario, of course your servlet should know about which state is active.
Akin Kaldiroglu
Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
Ok I finally got some documentation on this from someone here ... essentially it's a combination of state and MVC patterns.
The JSP being the view, Javabeans handle the model and we have controller Servlets there is also a state class which handles the state so the controller Servlet doesn't need to know the state .. it receives an HTTP request and invokes processRequest() on the instance of the State calss in the Session profile.
i think that's it ... the document is quite confusing I'll need to read through it again!
Alok Pota
Ranch Hand

Joined: Mar 07, 2001
Posts: 185
Can I you email the doc to me or give me the link where I can read it.
Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
I'm afraid it contains a lot of stuff confidential to the company. If I get time one day I might make a version of my own!
I agree. Here's the link:
subject: Web-State Pattern
It's not a secret anymore!