Java – Get URL Parameters in JSP page

This post shows you how to get value from URL parameters in a JSP page.

To do this, we simply use request.getParameter method, it takes a parameter name as an argument. The method returns the value of a request parameter as a String, or null if the parameter does not exist.

The code looks simple as below:

    String value = request.getParameter("parameter-name");

Here is a full example showing how to get value from URL parameters in JSP page.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Java - Get URL Parameters in JSP page</title>
            String value = request.getParameter("animal");
            if (value != null) {
            } else {
                out.write("The parameter does not exist.");

Assuming that we are opening this url:

The output should be: