Hidden Form Fields

Hidden form field is used to maintain the session. It
is one of the way to maintain the session. In hidden form fields the
html entry will be like this : <input type ="hidden" name =
"name" value="">. This means that when you submit the
form, the specified name and value will be get included in get or post method.
In this session ID information would be embedded within the form as a hidden
field and submitted with the http post command.
In this program of hidden form fields firstly we are
making a jsp form or html form in which we are using the post method and where
the request will be submitted or controlled, it is done by a controller
SettingHiddenField.jsp, it is the jsp where the business will be
applied.
The code of the program is given below:
<HTML>
<HEAD>
<TITLE>Submitting Hidden Fields</TITLE>
</HEAD>
<BODY>
<H1>How to use a Hidden fields </H1>
<FORM ACTION="SettingHiddenField.jsp" METHOD="post">
Enter your name : <input type ="text" name = "name" value = "">
<input type="hidden" name="hidden" value="You are most Welcome!">
<input type="submit" value="submit">
</FORM>
</BODY>
</HTML>
|
<HTML>
<HEAD>
<TITLE>Reading Hidden Controls</TITLE>
</HEAD>
<BODY>
<H1>Reading Hidden Controls</H1>
<%
String string = request.getParameter("name");
String text = "";
if(request.getParameter("text1") != null) {
out.println(string + "The hidden text is:" +request.getParameter("text1"));
text = request.getParameter("text1");
}
%>
<FORM ACTION="GettinHiddenField.jsp" METHOD="post">
<input type="text" name="text1">
<input type="hidden" name="hidden"
value="<%= text%>">
<input type="submit" value="Set Hidden Text">
</FORM>
</BODY>
</HTML>
|
<HTML>
<HEAD>
<TITLE>The Hiddern Fields</TITLE>
</HEAD>
<BODY>
<% out.println(request.getParameter("name"));%>
<H1>We can read hidden fields</H1>
The hidden text is:
<% out.println(request.getParameter("hidden")); %>
</BODY>
</HTML> |
The output of the program is given below:

After adding the name the output will be.

Download this example.

|