Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
State is an important concept to be aware of in all types of programming. After all, conventional programming relies on being able to accurately persist what a program has done. Web programming is no different, and there are many important things to be aware of when managing state in a Web Application. In some cases you can get by perfectly fine assuming the state of a Web Application is kept consistent enough to perform adequately. However, a good Web Application programmer needs to understand why state management is an issue and how to always ensure it is done properly. It is the goal of this chapter to clearly define and illustrate how to appropriately manage state in a Web Application.
This chapter discusses the following topics:
Maintaining session state with HTTP, a stateless protocol.
The javax.servlet.http.HttpSession object and a proper look at session scope.
Persisting session state.
Cookies and saving bits of information in the client's browser.
Initializing session resources.
State and thread safety.
The javax.servlet.SingleThreadModel interface, which is something that should not be used.