Hi I have a Controller class in my spring boot application which has two methods that correspond to GET and POST requests for the same url, When the user makes a get request it returns an html page with a form which when submitted makes a post request to the same url, I'm able to receive the form data but the problem is that the application is not returning another page when hitting the url with post. Instead I'm getting a WhiteLable error on the browser and on the console I'm getting this error ->
DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
Below is the code snippet
@Controller
public class SimpleController {
@GetMapping("/index")
public String getRequest() {
return "simple.html";
}
@PostMapping("/index")
public String postRequest(String firstName, String lastName) {
System.out.println("The result is " + firstName + " " + lastName);
System.out.println("----------------------------------");
return "simple.html";
}
}
And this is what my HTML code looks like
<body>
<form action="index" method="POST">
<input type="text" name="firstName">
<input type="text" name="lastName">
<input type="submit" value="submit">
</form>
</body>