How to read the request param values in spring using HTTPServletRequest
34,083
Solution 1
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"):
Solution 2
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
Solution 3
You can use
request.getParameter("parameter name")
Author by
user1195292
Updated on July 21, 2022Comments
-
user1195292 almost 2 years
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.