Search⌘ K

POST request

Explore how to use POST requests to pass form data securely in a Spring Boot web application. Learn to create forms, handle parameters in servlets using doPost(), and forward data to JSP pages. Understand integrating a business service to retrieve and display player details based on user input.

In a GET request, parameters are passed as a query string in the URL. The routers and ISPs can see the parameters and read values as they are passed in a GET request. POST request is another type of HTTP request which is more secure. In this lesson, we will pass parameters through a form using a POST request. The POST request is not completely secure, but it is better than a GET request. Name of a player can be passed as part of the URL as well as part of the form. Now we will pass it through a form.

Creating a form

The first step is to create a form which will have fields for input parameters. We will create the form in welcome.jsp. Forms can be created using the <form> tag. We need to specify who will handle the information in the form. Since we want the PlayerServlet to handle this request, we will specify player.do as action. In our application, any request to player.do is handled by the PlayerServlet:

<form action="/player.do">

</form>

Text box input element

Next, we will create an input element of text type and specify the name of the parameter.

HTML
<form action="/player.do">
<input type="text" name="name"/>
</form>

This will create a text box and the value entered in the text box is stored in the name parameter.

Submit button

To pass the parameter to the web server, we need a submit button. To ...