Nearby lessons

20 of 34

Servlet - Session Management (Hidden Form Fields)

📌 What You Will Learn
  • 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

Example02
Loading editor…

SessionServlet1.java

Example03
Loading editor…

SessionServlet2.java

Example04
Loading editor…

SessionServlet3.java

throws ServletException,IOException

Example05
Loading editor…

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

Example06
Loading editor…

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.

Example07
Loading editor…

SessionServlet3.java

This method will be executed automatically at the time of request object destruction. ie just

after completing service() method.

Example08
Loading editor…
📝 Key Takeaways
  • Key ideas of Servlet - Session Management (Hidden Form Fields) explained simply
  • Ready-to-use code examples
  • Exam-style questions at the end

🧠 Test Your Knowledge

3 Questions
Progress: 0 / 3

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.