Hidden form field is used to store session information of a client. In this method, we create a hidden form which passes the control to the servlet whose path is given in the form action area. Using this, the information of the user is stored and passed to the location where we want to send data.
The main advantage of using Hidden form filed that it doesn’t depend on the browser. Even If the cookies are disabled or not hidden, form filed will work perfectly.
A complete example of Hidden form field method
In this method we are transfering the client detail from firstServlet to Second Servlet
Step by Step processing of the code
As you Deploy the project and run the code on the server following process goes on.
- Control goes to index.html file and a form is genrated on web browser and it will ask for your username.
- In index.html file form, action is FirstServlet so when you hit submit button, control goes to FirstServlet and your session is start.
- In FirstServlet request.getParameter(username), take the input from index.html where the field is username and print it on the browser.
- In firstServlet there is a hidden form field which again takes the input from browser and pass the control to second servlet.
- This method goes on for a number of different Servlet.
Note : This is the main disadvantage of Hidden form field method that you have to fill the form again and again for maintaining a client session.
- In Second Servlet we again use request.getParameter for getting input from FirstServlet page.
Advantage and Applications
- It can be used for anonymous session tracking.
- Hidden form field is supported in every Browser. This method of session tracking does not need any special configuration of the browser.
- All the information is stored in client browser, so it increases the security
- It works only for a sequence of dynamically generated forms. This breaks down with static documents, emailed documents, bookmarked documents, and browser shutdowns.
- You need to submit an extra form on each request.
- It’s complex than URL rewriting.
- This method use only texual information.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- @SafeVarargs Annotation in Java 9 with Example
- Servlet Collaboration In Java Using RequestDispatcher and HttpServletResponse
- URL Rewriting using Java Servlet
- How to add Image to MySql database using Servlet and JDBC
- Javax.servlet.http.Cookie class in Java
- Java Servlet and JDBC Example | Insert data in MySQL
- Difference between ServletConfig and ServletContext in Java Servlet
- Difference between Java Servlet and CGI
- Starting with first Servlet Application
- The HttpSession Interface in Servlet
- Life Cycle of a Servlet
- Difference between Servlet and JSP
- How to find and open the Hidden files in a Directory using Java
- Check if a File is hidden in Java
- Field getAnnotatedType() method in Java With Examples
- What is the difference between field, variable, attribute, and property in Java
- Duration ZERO field in Java with Examples
- Field getBoolean() method in Java with Examples
- Field equals() method in Java with Examples
- Field getDeclaringClass() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.