How to get URL parameters in JSP with request.getParameter
Codemia Knowledge Hub ·
Use the implicit request object: request.getParameter("name") returns the first value of a query string parameter (or null if it is absent), and request.getParameterValues("name") returns every value when the name repeats.
Query string format
Parameters sent with a form submission or page request arrive in the URL's query string:
request.getParameter
In JSP, request is an instance of javax.servlet.http.HttpServletRequest. Call request.getParameter(String name) for each value:
For http://example.com/page.jsp?param1=hello¶m2=world, the output is:
Parameters with the same name
A URL can repeat a parameter name:
request.getParameterValues(String name) returns all the values as an array:
Request methods for parameters
| Method | Description | Return Type |
request.getParameter(String) | Returns first value for a named parameter | String |
request.getParameterValues(String) | Returns all values for a named parameter | String[] |
request.getParameterMap() | Returns a map of parameters and their values | Map<String,String[]> |
request.getQueryString() | Retrieves the full query string | String |
URL encoding
Make sure parameter values are URL-encoded so special characters in them do not break the query string.
Defaults for missing parameters
Check for null to avoid a NullPointerException, and fall back to a default:
Escaping output to prevent XSS
Printing user-supplied values directly opens you to Cross-Site Scripting (XSS). Sanitize input, and use JSTL's <c:out> to escape HTML characters:
The implicit EL param object reads the request parameter. A bare ${param1} would look up a scoped attribute named param1, not the request parameter or the scriptlet variable.
Related reading
- How to get request URL in Spring Boot RestController
- How to get rid of Incremental annotation processing requested warning?
- How to get Spinner value?
- How to get Spring RabbitMQ to create a new Queue?
- How to get status code from webclient?
- How to get the concrete class name as a string?
- How to get the current date/time in Java
- How to get the current time in YYYY-MM-DD HHMISec.Millisecond format in Java?
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.