There are two commonly used methods to send and get back information to the web server.

GET Method:

This is the default method to pass information from browser to web server. It sends the encoded information separated by ?character appended to URL page. It also has a size limitation, and we can only send 1024 characters in the request. We should avoid sending password and sensitive information through GET method.

POST Method:

Post method is a most reliable method of sending information to the server. It sends information as separate message. It sends as text string after ?in the URL. It is commonly used to send information which are sensitive.

JSP handles form data processing by using following methods:

getParameter():It is used to get the value of the form parameter. getParameterValues():It is used to return the multiple values of the parameters. getParameterNames()It is used to get the names of parameters. getInputStream()It is used to read the binary data sent by the client. Example: In this example, we have taken a form with two fields.”username” and “password” with a submit button Action_form.jsp <%@ page language=“java” contentType=“text/html; charset=ISO-8859-1” pageEncoding=“ISO-8859-1”%>

Guru Form
UserName:
Password:
Action_form_process.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>Insert title here

Form Processing

Welcome User: <%= request.getParameter("username")%>

Explanation of the code: Action_form.jsp Code Line 10: Here we have defined a form and through which we have process the action to some other JSP. In action parameter, we add that JSP to which it has to be processed through GET method. Here we are using GET method to pass the information i.e username and password. Code Line 11-14: Here we are taking fields like username and password which are text fields, and we are getting the input from the user. This input can be fetched using getParameter method. Also, we have submit button with type submit type which helps us to pass the field values into action_form_process.jsp Action_form_process.jsp Code Line 14: Here we get the values of the input fields from action_form.jsp using request object’s getParameter method. When we execute the above code, we get the following output:

Output: In this example, we have taken a form with two fields.”username” and “password” with a submit button Action_form.jsp Action_form_process.jsp Explanation of the code: Action_form.jsp Code Line 10: Here we have defined a form and through which we have process the action to some other JSP. In action parameter, we add that JSP to which it has to be processed through GET method. Here we are using GET method to pass the information i.e username and password. Code Line 11-14: Here we are taking fields like username and password which are text fields, and we are getting the input from the user. This input can be fetched using getParameter method. Also, we have submit button with type submit type which helps us to pass the field values into action_form_process.jsp Action_form_process.jsp Code Line 14: Here we get the values of the input fields from action_form.jsp using request object’s getParameter method. When we execute the above code, we get the following output:

When we execute action_form.jsp, we get a form with two fields username and password and a submit button.Then after entering username and password, we can click on submit, and it processes to next page which gives output as Form processing page with a welcome message.