The javax.servlet.http.HttpServletRequest interface provides a getQueryString method that returns the query string that is contained in the request URL after the path. The query string consists of one or more parameter-value pairs separated by an ampersand (&).
Example 1: Suppose a user requests a URL http://www.example.com/search?q=java+development+tutorials&page=2. To retrieve the query string from this request using the getQueryString method, you can use the following code:
Example 2: Suppose a user requests a URL http://www.example.com/aboutus. As there is no query string present in this request, the getQueryString method will return null. You can use the following code to check this condition:
String queryString = request.getQueryString(); if (queryString == null) { System.out.println("No query string present in the request"); }
Output: No query string present in the request
Package library: javax.servlet.http.
Java HttpServletRequest.getQueryString - 30 examples found. These are the top rated real world Java examples of javax.servlet.http.HttpServletRequest.getQueryString extracted from open source projects. You can rate examples to help us improve the quality of examples.