Nearby lessons
20 of 34Servlet - Session Management (Hidden Form Fields)
- Understand Demo Program for session management by hidden form fields
- See complete working code examples
Session Management (Hidden Form Fields) is an essential part of the Java Servlet technology. This lesson explains Demo Program for session management by hidden form fields, SessionServlet1.java and SessionServlet2.java with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid.
Demo Program for session management by hidden form fields
login.html:
Demo Program for session management by hidden form fields
SessionServlet1.java
SessionServlet2.java
SessionServlet3.java
throws ServletException,IOException
SessionServlet3.java
session7
|-login.html
|-WEB-INF
|-classes
|-SessionServlet1.class
|-SessionServlet2.class
|-SessionServlet3.class
Listeners
Objective:
- Describe web container event life cycle model for the request,session and web application.
2.Create and configure Listener class for each scope
3.Create and configure attribute listener for each scope
4.For the given scenario identify proper attribute listener?
In the web application there may be a chance of occuring several events like
Request object creation
Request object Destruction
Session object creation
Session object Destruction
Context object creation
Context object destruction
Attribute addition in request scope
Attribute Removal in request scope
Attribute Replacement in request scope
.....
whenever these events occur,if we want to do particular operation automatically then we should
go for listeners.
i.e Listener listens the events and will perform certain operations automatically.
All Listeners are divided into 3 groups
- Request Listeners:
These listen events related to request.
There are 2 types of Request Listeners
- ServletRequestListener
- ServletRequestAttributeListener
- Session Listeners:
These listen the events related to session. There are 4 types of session listeners.
- HttpSessionListener
- HttpSessionAttributeListener
- HttpSessionBindingListener
- HttpSessionActivationListener
- Context Listeners:
These listen events related to context.
There are 2 types of context listeners
SessionServlet3.java
This listener listens life cycle events of request object like creation and destruction.
This interface defines the following 2 methods.
1.public void requestInitialized(ServletRequestEvent e)
This method will be executed automatically at the tine of request object creation. i.e just before
starting service() method.
SessionServlet3.java
This method will be executed automatically at the time of request object destruction. ie just
after completing service() method.
- Key ideas of Servlet - Session Management (Hidden Form Fields) explained simply
- Ready-to-use code examples
- Exam-style questions at the end