3
Could someone please explain to me how to correct my JSP error?
This form will serve to register products in my system, it receives a list of product categories from the database.
My Product Controller Ntroller.java:
import java.util.Map;
import org.springframework.stereotype.Controller;
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
@RequestMapping("controllerProduto")
public class ProdutoController {
    @RequestMapping("produtoForm")
    public String loginForm(Model model){
        CategoriaProdutoDao dao = new CategoriaProdutoDao();
        model.addAttribute("lista", dao.listar());
        return "produtos/frmCadastroProduto";
    }
    /*@RequestMapping("/home")
    public ModelAndView home(ModelMap model){
        model.put("lista",dao.listar());
        System.out.println("categoria achada");
        return new ModelAndView("categoriaProduto",model);
    }*/
    @RequestMapping(value = "/inserirProduto", method = RequestMethod.POST)
    @ResponseBody()
    public String inserirProduto(@ModelAttribute("inserirProdutoForm")Produto produto, ModelMap model){
        ProdutoDao dao = new ProdutoDao();
        model.addAttribute("categoriaProduto", produto.getCategoriaProduto().getCdCategoriaProduto());
        model.addAttribute("descricao", produto.getDescricao());
        dao.adiciona(produto);
        return "produtoForm";
    }
}
My JSP:
    <%@ 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">
        <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">id</form:label></td>
    <td><form:select path="categoriaProduto" items="${lista}"  /></td>
</tr>
            <tr>
                <td colspan="2" align="center"><input type="submit" value="Register" /></td>
            </tr>
        </table>
    </form:form>
</div>
</body>
</html>
And the mistake that’s coming back to me:
HTTP Status 500 - An exception occurred processing JSP page /WEB-INF/views/produtos/frmCadastroProduto.jsp at line 18
type Exception report
message An exception occurred processing JSP page /WEB-INF/views/produtos/frmCadastroProduto.jsp at line 18
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/produtos/frmCadastroProduto.jsp at line 18
15:             <table border="0">   
16:             
17:             <tr>
18:         <td><form:label path="descricao">Nome Produto</form:label></td> 
19:         <td><form:input path="descricao" /></td>
20:     </tr>
21:     <tr>
I believe that
${lista}contains a list of some class of yours. I’m not sure, but in this case you do not need to set the attributesitemValue="id"itemLabel="nome"ofform:select? According to the documentation, should work, but it doesn’t hurt to try :)– gabrielhof
I’ve already made the appropriate modifications to my form:select, thank you!
– Luiz Fernando Augusto