Javatpoint Logo
Javatpoint Logo

2) Hidden Form Field

In case of Hidden Form Field a hidden (invisible) textfield is used for maintaining the state of an user.

In such case, we store the information in the hidden field and get it from another servlet. This approach is better if we have to submit form in all the pages and we don't want to depend on the browser.

Let's see the code to store value in hidden field.

Here, uname is the hidden field name and Vimal Jaiswal is the hidden field value.


Real application of hidden form field

It is widely used in comment form of a website. In such case, we store page id or page name in the hidden field so that each page can be uniquely identified.


Advantage of Hidden Form Field

  1. It will always work whether cookie is disabled or not.

Disadvantage of Hidden Form Field:

  1. It is maintained at server side.
  2. Extra form submission is required on each pages.
  3. Only textual information can be used.

Example of using Hidden Form Field

In this example, we are storing the name of the user in a hidden textfield and getting that value from another servlet.

Hidden Form Field in Servlet

index.html

FirstServlet.java

SecondServlet.java

web.xml





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA