Saturday, February 21, 2026
HomeLanguagesJavaServlet – Hidden Form Field

Servlet – Hidden Form Field

The Server embeds new hidden Fields in every dynamically generated From page for the client. when the client submits the form to the server the hidden fields identify the client. Hidden Box is an invisible text box of the form page, hidden box value goes to the server as a request parameter when the form is submitted.

Syntax for hidden fields:

<input type=hidden name=”name” value=”value”>

  • name: is a hidden box name or Request parameter Name.
  • value: is a hidden box value or Request parameter value.

Advantages of using Hidden Form Field

  • It’s simple.
  • No effect on security level setting in browsers.
  • Basic HTML knowledge is sufficient to work with this technique.
  • This technique work with all server-side technologies like Servlet, JSP, ASP.net, PHP, etc.

Disadvantages of using Hidden Form Field

  • The documents need to be embedded the data inside, waste bandwidth. you have to embed the result from the previous page on the next page.
  • Everyone can see the embedded data by viewing the original source code.
  • We cannot store all kinds of java objects in hidden boxes except text/string values.
  • Hidden boxes travel over the network along with the request and response. the indicates more network traffic.

Example

In this example, we are showing the user name and the visited time.

home.jsp

HTML




<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  
   <head>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
       <title>Home Page</title>
   </head>
  
   <body>
       <%
           java.util.Date today= new java.util.Date();
           java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("hh:mm;ss");
           String str =sdf.format(today);
         %>
  
         <form action ="welcome.jsp" metgod="post">
             Enter your name:<input type="text" name="username"/>
             <input type="hidden" value="<%=str%>" name="visittime"/>
             <br>
             <input type="submit" value="Show Message"/>    
          </form>
   </body>
  
</html>


Welcome.jsp

HTML




<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  
   <head>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
       <title>JSP Page</title>
   </head>
  
   <body>
       <%
           String name=request.getParameter("username");
           String time=request.getParameter("visittime");
        %>
        <h3>Hello <%=name%>,Welcome to our Page !</h3>
        You visited Home page at <%= time %>
   </body>
  
</html>


Output:

OutputOutput

 

Output

                                               

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS