Sobes.tech
Junior — Middle

How can parameters be extracted from an incoming HTTP request?

sobes.tech AI

Answer from AI

In Java, parameters from an incoming HTTP request can be extracted in several ways depending on the framework used:

  • In the Servlet API, through methods like request.getParameter("paramName") to obtain parameters from the query string or form.
  • In Spring MVC, using annotations such as @RequestParam for request parameters, @PathVariable for path variables, and @RequestBody for the request body.

Example with Spring MVC:

@GetMapping("/users")
public String getUser(@RequestParam String id) {
    // id will be extracted from the request parameters
    return "User id: " + id;
}
How can parameters be extracted from an incoming HTTP… - sobes.tech