Session Management Using Hidden Form Field in Servlet with Example. - Javastudypoint

Sunday, October 14, 2018

Session Management Using Hidden Form Field in Servlet with Example.

In this tutorial, we will learn another technique to manage the session. In the previous technique, we have learned session management using cookie class. Here we will learn second techniques Hidden Form Field to manage the session. Before discussing this technique in details let's first understand about Hidden Form Field.



What is the Hidden Form Field?

One way to support session tracking is to use Hidden Form Field. As the name implies, these are fields added to an HTML form that is not displayed in the client browser. They are sent back to the server when the form that contains them is submitted. You include Hidden Form Fields like this.


  <input type="hidden" name="username" value="javastudypoint"/>

In a sense, hidden form defines constant variables for a form. To a  servlet receiving a submitted form, there is no difference between a hidden field and a visible field. With hidden fields, we can rewrite our shopping cart servlets so that users can shop anonymously until checkout time.

Read: Session Management using Cookie in Servlet

Advantages of Hidden Form Field:

Hidden fields are supported in all the popular browser, they demand no special server requirement, and they can be used with the client that haven't registered or logged in.

Disadvantage of Hidden Form Field:

The major disadvantage of this technique, however, is that the session persists only through a sequence of dynamically generated forms. The session cannot be maintained with the static document, emailed documents, bookmarked documents or browser shutdown.

Hidden Form Field Example: 

In this example, we are storing username and password in a hidden text field and getting this information in another servlet.
index.html file:

Hidden Form Field in Servlet


HiddenFormField1.java file:


Hidden Form Field in Servlet




HiddenFormField2.java file:

Hidden Form Field in Servlet





Web.xml file:

Hidden Form Field in Servlet








Hidden Form Field in Servlet




Hidden Form Field in Servlet





Hidden Form Field in Servlet



You may also like:


No comments:

Post a Comment