Hidden Form Field in JSP


This article explains how to read hidden form fields in JSP. The Netbeans IDE is used to create the sample application.

Hidden form fields

This field is basically used for maintaining the session. In hidden form fields the HTML entry will be like this.

<input type="hidden" name="SomeName" value="SomeValue">

This field is embedded with the submit button, in other words when we click on the submit button it is encoded with a get/post request of the form page and sends it to another page. If we want this information then we call it using the "request.getParameter" attribute.

This field plays and important role in web development; for example it is used to maintain a session, used in authentication, etcetera.

Let's start creating this app

Use the following procedure to create this sample app.

Step 1

Open the NetBeans IDE.

NetBeans IDE

Step 2

Choose "Java web" -> "web application" as shown below.

Java Web App

Step 3

Type your project name as "GetHiddenFormApp" as in the following.


Step 4

Now choose your Java version and server wizard as shown below.

Server and Version wizard

Step 5

Now replace the default code of the "index.jsp" file with following code.


<!DOCTYPE html>



        <title>Hidden Form</title>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <meta name="viewport" content="width=device-width">



        <form action="printhiddendata.jsp" method="post">

        Enter your name: <input type="text" name="uname">

        <br><input type="hidden" name="hide" value="What are you doing">

        <input type="submit" value="Go">




Step 6

Create another JSP page named "printhiddendata.jsp" and provide following code there.






            <% out.println(request.getParameter("uname"));


            <br>Hidden Fields Are:

            <% out.println(request.getParameter("hide"));





Step 7

Now our application is ready to run.

Right-click on the "index.jsp" file and select "Run". The following output will be generated.


Step 8

Now provide your name; I typed in my name as in the following.


Step 9

After clicking on the "submit" button you will see the following output.

Hidden Data