I have an odd exception in our application and I'd like to log when it occurs and include the complete request string including the parameters.
When I try
log.warn("Weird request " + request.getRequestURL());
I get the request string but not the parameters which were included with ? and &.
example:
/testRequest.do?param1=1¶m2=2
I only see
/testRequest.do
Can I get this whole string somewhere?
GET parameters (also called URL parameters or query strings) are used when a client, such as a browser, requests a particular resource from a web server using the HTTP protocol. These parameters are usually name-value pairs, separated by an equals sign = .
To get all request parameters in java, we get all the request parameter names and store it in an Enumeration object. Our Enumeration object now contains all the parameter names of the request. We then iterate the enumeration and get the value of the request given the parameter name.
Parameters can be passed in GET Request, if you are not sure how to do a GET Request using Postman, please take a look at the previous article How to make a GET Request. Since now you know how to make a GET request, we will move ahead with sending parameters in a GET request.
See HttpServletRequest#getQueryString()
If you want the whole string, you'll have to append the request url and the query string together as there is no method to get the whole thing.
System.out.println(request.getRequestURL().append('?').append(request.getQueryString()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With