Sending data to servlet HTTP get method

Here we will discuss Servlet HTTP get method

What is a Servlet?

A servlet is a Java-based program that runs on a web server. It handles client requests and generates dynamic web content. Servlets are an integral part of Java EE (Enterprise Edition) and are widely used for web development.


The HTTP GET method is one of the standard request methods used by web browsers to request data from a web server. It appends data to the URL in the form of query parameters. This method is commonly used when you want to retrieve data from the server without altering any server-side resources.

Generally, HTTP is used to get information from the server, but for getting specific information based on id or user name or based on query string we send id, user name, or search term query to server.

Here we have created a form tag and two text boxes to take input age and name from the user.
<form action=”SubmitServlet”> is sending data to SubmitServlet.

By default form method is get so it will call doGet() of SubmitServlet.
<form action=”SubmitServlet”> is equivalent to <form action=”SubmitServlet” method=”get”>
While using http get method the submitted content(name and age) is displaying on address bar.

servlet HTTP get method Project Explorer
servlet HTTP get method Project Explorer


Enter your name and age in Servlet Read data from Servlet doGET method

Certainly! Below is the Java code for a servlet named “SubmitServlet.” This servlet handles HTTP GET requests and responds with a simple HTML page displaying the user’s name and age, which are obtained as request parameters.

This servlet listens for requests at the URL path “/SubmitServlet” and responds by displaying the user’s name and age in an HTML format. The “doGet” method processes the HTTP GET request, retrieves the user’s input, and generates the response.

A ServletException is an exception that can occur in a Java web application when there’s an issue or error related to the execution of a servlet.

An IOException stands for Input/Output Exception. It’s a common exception in Java and other programming languages that typically occurs when there’s a problem with reading from or writing to external resources like files, network connections, or streams.

Address bar shows http://localhost:8084/ServletTutorial2/SubmitServlet?name=Ram+Kumar&age=22
after ? it is showing submitted data.

servlet HTTP get method form
servlet HTTP get method form
servlet HTTP get method showing data
servlet HTTP get method showing data

Here we discussed Sending data to servlet HTTP get method. Hope you are able to understand this.

Read More

html/jsp page response in ajax get method

Servlet Maven Configuration Example