2
I wish you could help me with this problem that is occurring in my application.
Below is the code:
package br.com.estoque.Controller;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import br.com.estoque.Dao.CategoriaProdutoDao;
import br.com.estoque.Dao.ProdutoDao;
import br.com.estoque.Modelo.Produto;
@Controller
public class ProdutoController {
@RequestMapping("produtoForm")
public ModelAndView entradaForm(){
ModelAndView mav = new ModelAndView();
CategoriaProdutoDao dao = new CategoriaProdutoDao();
mav.setViewName("produtos/frmCadastroProduto");
mav.addObject("lista",dao.listar());
mav.addObject("produto",new Produto());
return mav;
}
@RequestMapping(value = "/inserirProduto", method = RequestMethod.POST)
public String save(@ModelAttribute("produto") Produto produto){
ProdutoDao dao = new ProdutoDao();
dao.adiciona(produto);
return "produtos/frmCadastroProduto";
}
}
My frmCadastroProduct
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration</title>
</head>
<body>
<div align="center">
<form:form action="inserirProduto" method="post" modelAttribute="produto">
<table border="0">
<tr>
<td><form:label path="descricao">Nome Produto</form:label></td>
<td><form:input path="descricao" /></td>
</tr>
<tr>
<td><form:label path="categoriaProduto">Selecione a categoria de produto</form:label></td>
<td><form:select path="categoriaProduto">
<form:option value=" - " label="--Please Select"></form:option>
<form:options items="${lista}" itemValue="cdCategoriaProduto" itemLabel="descricao"/>
</form:select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Register" /></td>
</tr>
</table>
</form:form>
</div>
</body>
</html>
Error screen that is turning me...
Luiz, welcome to [en.so]! What is the URL of error 400?
– utluiz
http://localhost:8080/Stock/inProduct is this one! , if you need more details to understand the problem I command!!
– Luiz Fernando Augusto
I compared to a system I have here and apparently everything is right, except that I can not check your settings. It even runs the method
inserirProduto()
? If you go through there, the problem is probably in the redirect at the end. You tme a Tiles configured took
?– utluiz
And remove that note
@ResponseBody
, it is usually used to return Json. You have another record that works withPOST
?– utluiz
I’ve already removed
@ResponseBody
, I do own a JSP called ok. Method adds() does not get to be executed, as it does not return an msg in the console I put in the execution of the method. If you need more information about my settings I can post here!! I’m a little desperate because I need to deliver this system by the end of the year, and this is just the first screen of registration... thanks for the help!!!– Luiz Fernando Augusto
if Voce can pass me as the controller of this your system you compared was, it would be of great help too!
– Luiz Fernando Augusto