Java Servlets   «Prev  Next»

Lesson 3HTTP Stateless Information
ObjectiveConsequences of Stateless Interactions

Consequences of Stateless Interactions and HTTP Information

Java Servlet API

HTTP is only one of many protocols in use on the Internet. There are literally hundreds of ways for two pieces of software to exchange information over the network.
One way to differentiate them is to characterize them as either
  1. stateful or
  2. stateless.
In a “ stateful” exchange of information the client and the server maintain their connection until all communication is finished and the connection is specifically terminated. It is rather like a telephone call. Say I want to call you and get the phone numbers of two of our mutual friends.

It might go like this:
1) Your phone rings
1) Your phone rings

2) You say hello.
2) You say "Hello" , I say "Hi, it's Kate!"

3) Hey Kate, great to hear your voice.
3) You say, "Hey, Kate, great to hear your voice!"
I ask, "Do you have Jim's phone number?"


4) Hang on, I'll look, yes here it is , 555-1234
4) You say "Hang on, I will look, ..., yes here it is, 555-1234."
I say "Terrific! What about Sue's?"

5) Sorry, she changed it a while ago.
5) You say "Sorry, she changed it a while ago and I never got the new number."
I say "Thanks anyway. Maybe I will ask Jim when I call him. I have got to run."

6) Sure, talk to you soon.
6) You say "Sure. Talk to you soon."
I say "Bye", and hang up.


Http Stateless Information

Stateless Information

The purpose of these diagrams is to give you the general idea. Now if I were to get the same information from you in a stateless way, I would have to tell you everything you needed to know in every request. We would not keep a connection or session going between requests.

HTTP is stateless. Whenever a browser requests a file, the server sends back the file and the connection drops.
If the user follows a link on that page to a file on the same server, the browser contacts the server again and asks for that new file, but the server does not know that the browser just requested a file moments ago. Each request is completely independent.

How does HTTP work?
The HTML for your Contact page is likely to be the same no matter how many times this user has been to your site.
But if people are buying books or clothes, you need to know that this browser request is from the same person who has already ordered $200 worth of your product, and now they want to order more. This is called maintaining state. That way, you can give people a running total of their order or any number of personalized pages that are right for them. In the next lesson, CGI server-side technology will be discussed.

Servlet Protocols - Quiz

Take a quiz about HTTP and its communication protocol.
Servlet Protocols - Quiz

Java Servlets