How to read GET request parameters in servlet jsp

 Posted On  | Yashwant Chavan 

In this tutorial, You will learn how to read GET request parameters in servlet and jsp. This post will help you to setup Java web application using servlets and jsp.

Servlet Jsp - Eclipse Project set up

Read GET request parameters in servlet jsp - Eclipse Project Setup


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">

package com.technicalkeeda.servlet;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloController extends HttpServlet {
    private static final long serialVersionUID = 1 L;

    public HelloController() {


    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String firstName = request.getParameter("firstName");
        String lastName = request.getParameter("lastName");

        Map < String, String > name = new HashMap < String, String > ();
        name.put("first_name", firstName);
        name.put("last_name", lastName);

        request.setAttribute("name", name);

        RequestDispatcher rd = request.getRequestDispatcher("result.jsp");
        rd.forward(request, response);



<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.Map" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
      <h2>Result Page</h2>
         Map<String,String> name = (Map<String,String>) request.getAttribute("name");
      <table cellpadding="1"  cellspacing="1" border="1" bordercolor="gray">
            <td>First Name</td>
            <td>Last Name</td>
            <td><%=name.get("first_name") %></td>
            <td><%=name.get("last_name") %></td>

Deploy and Execute

Enter the Url http://localhost:8080/ServletJspExamples/hello?firstName=Yashwant&lastName=Chavan in your browser. Here we have two parameters "firstName" and "lastName" along with its values.

read GET request parameters in servlet jsp - output

© 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0443 seconds.