Servlet Hidden Form Field

In this tutorial you will learn about the Servlet Hidden Form Field and its application with practical example.

Servlet Hidden Form Field

Hidden form field can be used for session management for a particular client. In this case a hidden textfield is used to maintain the state of an user. We store the information in hidden form field and get it from another servlet.

Syntax :-

The syntax which is using to store the data in hidden field is below.

The advantage of this thing over cookie: It works even cookie is disabled.

There are also some disadvantage of this thing: We need extra form submission on each page, it maintained from server side.

Example: Let’s understand it by an example.

  1. html: This will be our welcome file for hidden form field.

2. FirstServlet.java: From this servlet file we will store hidden data. Check below code.

3. SecondServlet.java: We will get our hidden data here. Check below code.

Output :-

When we will run this simple code so we will get output like below images.

index.html

This is output of index.html file.

image001

This will come when we will click on go button of index.html file.

image003

This output comes for SecondServlet class, here we got our hidden field data.

image005

In this tutorial we have learn about the Servlet Hidden Form Field and its application with practical example. I hope you will like this tutorial.