10:21 pm - Friday March 22, 2019

Hidden form fields in Servlet

Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Hidden Form fields: 

Hidden form is a form of session tracking which saves the information in client browser itself.

We uses hidden box in html to hide the session information from client.

We cannot use this type of session for secure data because  when a client views the source code of the html page the session information can be view by all.

<input type =”hidden” name =”session” value=”sessionid”/>/

In servlet to get session information:

 String value = request.getParameter(“session”);

One way to support anonymous session tracking is to use hidden form fields. As the name implies, these are fields added to an HTML form that are not displayed in the client’s browser. They are sent back to the server when the form that contains them is submitted.

In case of hidden form field an invisible text field is used for maintaining state of an user.

  Project Structure:













package com.candid;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

* Servlet implementation class Hidden
public class Hidden extends HttpServlet {
private static final long serialVersionUID = 1L;

* Default constructor.
public Hidden() {
// TODO Auto-generated constructor stub

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
*      response)
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
PrintWriter out = res.getWriter();
out.println("<body bgcolor=pink>");
out.println("<font color=blue size=6>");
String str1 = req.getParameter("loginId");
String str2 = req.getParameter("company");
out.println("<form action=Hidden>");
out.println("your login name is " + str1);
out.println("<br>your Company is " + str2);
.println("<p>The value of Login name is stored in the Hidden box</p> ");
out.println("<input type=hidden name=loginId value=" + str1 + ">");
out.println("<input type=submit value=press>");


* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
*      response)



<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<body bgcolor="pink">
<form action="Hidden" method="get"><font color="blue" size="6">
This method is to Explain the Use of Hidden </br>
Enter your Login Name <input type=text name=loginId></br>
Enter your Company name <input type=text name=company></br>
<input type=submit value=click> </font></form>


DOWNLOAD+SOURCE CODE                                                                                                                                                   BACK

Filed in: Z-A Servlet codes

No comments yet.

Leave a Reply