NET Centric Computing · Unit 6
State Management and HTTP Protocol
Exam-focused notes for State Management and HTTP Protocol (NET Centric Computing, BIT351): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.
State Management and HTTP Protocol in short
Web pages are sent over HTTP, which forgets every request as soon as it ends. Web apps still need to remember who the user is, what is in a cart, and what was typed. State management techniques solve this.
What this unit covers
- Stateless HTTP protocol
- Cookies definition and uses
- Hidden fields purpose and usage
- Session state management
- State management techniques
State management techniques
Hidden fields purpose and usage
2080 · 5 marks
When do you need hidden field? Explain with an example. [5]
Cookies definition and uses
2081.1 · 5 marks
Define cookies. What are the uses of hidden fields? [5]
Show solved answerHide answer
Cookies and Hidden Fields
Cookies (Definition)
A cookie is a small piece of text data that a web server sends to a client's browser, which the browser stores locally on the user's machine. When the browser makes subsequent requests to the same server, it automatically sends the stored cookie back, allowing the server to identify and remember the user across multiple requests.
Key characteristics of cookies:
- Stored on the client side (user's browser/machine)
- Have an expiry date/time (session cookies expire when browser closes; persistent cookies have a set expiry)
- Associated with a specific domain and path
- Set using the
Set-CookieHTTP response header - Sent back to the server via the
CookieHTTP request header
Example:
Set-Cookie: username=JohnDoe; expires=Fri, 31 Dec 2025 12:00:00 GMT; path=/
Common uses of cookies:
- User authentication and session management
- Storing user preferences
- Tracking user behavior
- Shopping cart persistence
Hidden Fields
A hidden field is an HTML form element (<input type="hidden">) that stores data within a web form but is not visible to the user on the browser screen. The data is submitted to the server when the form is submitted.
Syntax:
<input type="hidden" name="userID" value="1023">
Uses of Hidden Fields
| Use | Description |
|---|---|
| State Management | Maintain state information (e.g., user ID, session token) across multiple page requests without cookies |
| Passing Data Between Pages | Transfer data from one page to another through form submission without displaying it to the user |
| Security Tokens (CSRF Protection) | Store anti-CSRF tokens to validate that form submissions are legitimate |
| Tracking Form Progress | In multi-step forms (wizards), carry forward data collected in previous steps |
| Storing Record IDs | Pass database record IDs (e.g., product ID, order ID) back to the server during form submission |
| Preserving Original Values | Store original field values to detect changes made by the user before update |
Key Difference
| Feature | Cookies | Hidden Fields |
|---|---|---|
| Storage | Client's browser/disk | Inside HTML form |
| Visibility | Not visible in page | Not visible on screen but visible in page source |
| Persistence | Can persist across sessions | Only available during form submission |
| Sent to server | With every HTTP request | Only on form submission |
Session state management
2081.1 · 5 marks
What is the use of session state? Discuss about single page application. [5]
Make Unit 6 stick
Practice BIT351 with flashcards & quizzes