java2db

How to get the form data in servlet (form input values)



In web applications, the user enters a valid data in the user interface(UI) and send it to the server.The server side java technology(Example:Java Servlet) receive the data and sends back response to the clients.Therefore to get the form data in servlet,The Servlet API provides appropriate methods.

 

The user interface my be a HTML , JSP or any other.In general the user interface contains the following input fields.
get the form data in servlet Text Box : It allows the user to type input text from the keyboard.
get the form data in servlet Password Box :It takes the text, and hides it by replacing a special symbols(Example : *).
get the form data in servlet TextArea : It takes multiple lines of text (Example :User Comments).
get the form data in servlet Radio Button:It allows user to select any one of the Radio Buttons group.
get the form data in servlet Check Box : It allows user to select more from a group of Check Boxes.
Select/Combo Box: User can select any one from the list of items.
ListBox : User can select more from the list of items.
Button : Allows user to perform an action.
Submit: Allows user to submit a form fields.

 

In the below example, we are getting the Text Box and Password Box values only.
get the form data in servlet

 

Text Box declaration in UI side :

Password Box declaration in UI side :

 

get the form data in servlet Code to get the form data in servlet :

The servlet container creates the HttpServletRequest object once the servlet class initialized successfully.

Call the field data with its logical name.

 

get the form data in servlet Example application to get the form data in servlet :

 Basic requirements that are required to run the application :

Softwares :
Java (Download).
GlassFish server (Download).
Eclipse IDE (Download).
Jar files:
javax.servlet.jar (Download).
javax.servlet.jsp.jar (Download).
Source files :
index.jsp
GetInputServlet.java
web.xml

 

get the form data in servlet index.jsp

get the form data in servlet GetInputServlet.java

web.xml

 

Execution Result:




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 )
Hidden form field in servlets ( Servlet session tracking )
Request attributes in servlet with an example ( Attribute scope )
Session attributes in servlet with example (Attribute scope)
ServletConext Attributes in servlet ( Attribute scope )
   [will not be published]



^ <