Creating a Servlet
Explore how to create a servlet class in Spring Boot that handles HTTP GET requests using the HttpServlet class. Learn to map a URL to the servlet with annotations, send HTML responses, and configure your web application to run with an embedded Tomcat server. This lesson guides you through a basic request-response cycle essential for enterprise web applications.
We'll cover the following...
A servlet is a Java class that can take in a request and return a response. The input to the servlet is a request, and the output is a response. In a web application, we are talking about HTTP requests and HTTP responses. When something is typed in the address bar of a browser, it sends a request to the web server. The web server returns a response based on the request, and the browser displays the page.
So far, we have created a web.xml file that defines a welcome file, player.do, for our web application. When http://localhost:8080 is typed in the browser, the browser creates a GET request and sends it to http://localhost:8080/player.do. We want this request to be mapped to a servlet which sends some response back to the browser.