I want to read the requestParams data from the url using HttpServletRequest
http://localhost:8080/api/type?name=xyz&age=20
The method in my controller will not have @RequestParam defined,it will be just
@RequestMapping(value = "/**", method = RequestMethod.GET)
public ResponseEntity<String> getResponse(
final HttpServletRequest request) {}
I want to read using request only the params not the entire url.
first, why you are define:
@RequestMapping(value = "/**", method = RequestMethod.GET)`
?
maybe you should use:
@RequestMapping(value = "/api/type", method = RequestMethod.GET)
and read param :
request.getParameter("name");
request.getParameter("age"):
xiang is right for your exact question: "I want to read using request only the params"
But why do you want to make it so difficult. Spring supports you, so you do not need to handle the request object by yourself for such common tasks:
I recommend to use
@RequestMapping(value = "/*", method = RequestMethod.GET)
public ResponseEntity<String> getResponse(
@RequestParam("name") String name
@RequestParam("age") int age){
...
}
instead.
@See Spring Reference Chapter 15.3.2.4. Binding request parameters to method parameters with @RequestParam
You can use
request.getParameter("parameter name")
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