Witam. Dopiero zaczynam naukę ze Springiem MVC i mam problem. A więc tak, mam na początek taki prościutki formularz.
<form action="/show" method="post">
<input name="username" />
<input value="submit" type="submit" />
</form>
oraz prościutki kontroler
@PostMapping("/show")
public String show(@RequestParam String username){
System.out.println(username);
return "index";
}
Po wypełnieniu formularza pojawia się error
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
Jednak w konsoli nazwa podana przez użytkownika normalnie wyświetla się czyli metoda normalnie się wywołała. Problem jest chyba ze zwróceniem z powrotem strony index.html. W pliku application.properties mam podany prefix i suffix. Plik index.html umieściłem w folderze static w którym dodałem folder webapp i tam znajduje się owy plik. A prefix i suffix prezentują się tak
spring.mvc.view.prefix=/webapp/
spring.mvc.view.suffix=.html
Dodam, że na metodzie GET która również zwraca tą stronę wszystko normalnie działa.
Shalom