-1
The method you are sending by clicking the button is a GET
but in my Javascript step as method POST
and in the Controller
he expects to receive a method POST
also.
My JS:
function criaCategoria() {
let tituloCategoria = document.getElementById("tituloCategoria").value
data = {
'tituloCategoria': tituloCategoria
}
fetch('/FlowerLiu/nota', {
method: 'POST',
body: JSON.stringify(data)
})
}
My Controller to create category:
@RequestMapping(value = "/categoria", method = RequestMethod.POST)
public @ResponseBody String criaCategoria(@RequestBody String rawJson) {
System.out.println("CRIO");
JSONObject parsedJson = new JSONObject(rawJson);
CategoriasDAO dao = new CategoriasDAO();
Categoria categoria = new Categoria();
categoria.setTitulo(parsedJson.getString("tituloCategoria"));
dao.adicionaCategoria(categoria);
dao.close();
return "home";
}
My button on JSP:
<a href="categoria"><button onclick="criaCategoria()">Criar Categoria</button></a>
The moment I click on the "Create Category" button, I get the error:
405 - "Request not supported method"
as if the method sent was GET
, but I expected a POST
.
Welcome to Stackoverflow Victor. And at the moment the error occurs?
– Pedro Gaspar
@Pedrogaspar The moment I click on the button to create, I get error 405 as if the sent method was GET but I expected a POST
– Vitor Satyro Vitturi