Issue
I have some input fields in my jsp page,l want to know is it possible for values passed in those fields to be passed as URL.
I tried using @RequestParam and @PathVariable on same variable to try to retrive it and put it as URI but it didnt work
This is my jsp page form:
<body>
<form action="welcome/" method="post">
<input type="text" name="name" value="">
<input type="submit" value="go">
</form>
</body>
And this is my Controller handler method:
@PostMapping(value = "/welcome/{name}")
public String welcomeAgain(@PathVariable @RequestParam("name")String name){
return "welcome";
}
Solution
To get the value passed in URL you can use @PathVariable
normally with GET
request.
http://localhost:8080/user/101
@RequestParam
normally used with POST
request for accessing the query parameter values
http://localhost:8080/user/101?param1=10¶m2=20
@PostMapping(value = "/welcome/{name}")
public String welcomeAgain(@PathVariable("name") String name){
return "welcome " + name;
}
Answered By - Romil Patel