Servlet Hidden Form Field

Hidden form field is an invisible field that saves the information regarding the state in client browser. As this information is invisible so client can’t see it but it is visible to servlet.

These fields are added to HTML form and when client submit form then these fields are also sent to the server with form.

Example of Hidden Form Field

index.html

<center>
<h1>Click to check hidden data</h1>
<form action="serv" method="post">
<input type="hidden" name="website" value="TutorialandExample">
<input type="submit" value="check out">
</form>
</center>

DemoHiddenForm.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;
@WebServlet("/serv")
public class DemoHiddenForm extends HttpServlet {
protected void doPost(HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException {
 String web = req.getParameter("website");
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<h1><center>Welcome to " + web+"</center></h1>");
}
}
Output: