java2db

Hidden form field in servlets ( Servlet session tracking )



Hidden form field is a HTML form field.It is an invisible text box and it also included in the request like other fields (Example : text,radio,check…) while submitting the form.

 

Hidden form field is useful to hide user data from other users in HTTP request and response.It can work for both GET and POST methods of a servlet.

It works for a page that generated dynamically by a form submission.

 

Hidden form fields in servletsSyntax :

<input type=”hidden” name=”logical_name” value=”string_value”/>

 

Hidden form fields in servlets Example for hidden form field :

Hidden form fields in servlets Directory structure :

Hidden form fields in servlets

 

 

Hidden form fields in servlets index.jsp

Hidden form fields in servlets QuestionServlet.java

Hidden form fields in servlets ResultServlet.java

Hidden form fields in servlets web.xml

Hidden form fields in servlets Execution result:

Enter URL (http://localhost:8080/HiddenFormApp)  in the browser window’s address bar.Hit enter button.

The sendRedirect

Fill the details and click submit button.The response comes with a question according to your selection.
The sendRedirect

Enter the correct answer and click submit button.The final result page comes like below.
The sendRedirect

create a servletWe can use hidden form field in JSP/HTML forms directly by passing a value to it.



Related Posts :
Kill or invalidate session using session id ( concurrent login )
Servlet Filter ( Request and Response filters in servlets ) example
URL rewriting in servlets ( Servlet session tracking )
Servlet Cookies ( Servlets session tracking with cookie )
Request attributes in servlet with an example ( Attribute scope )
Session attributes in servlet with example (Attribute scope)
ServletConext Attributes in servlet ( Attribute scope )
The sendRedirect (servlets are in different web applications)
   [will not be published]



^ <