Illegal use of <when>-style tag without <choose> as its direct Parent

Asked

Viewed 97 times

0

I am developing a web application using jsp and Servlet page and I would like to show the data of my Servlet in two repeat structures one with the produots and the other with the plots but this error appears.

Illegal use of <when>-style tag without <choose> as its direct parent

Servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    //response.getWriter().append("Served at: ").append(request.getContextPath());


     try {

            ProdutosDAO dao = new ProdutosDAO();



         String codigo = request.getParameter("codigo");
      int codigo2=   Integer.parseInt(codigo);


codigo2=1;

           List listaProdutos = dao.mostrarProdutos(codigo2);
           request.setAttribute("listaTodosProdutos", listaProdutos);




           List listaParcelas = dao.mostrarParcelas(codigo2);
           request.setAttribute("listaParcela", listaParcelas);

           RequestDispatcher rd =request.getRequestDispatcher("/Compra.jsp");
           rd.forward(request, response);

       } catch (Exception e) {
           System.out.println("Erro na servelet" + e);
       }
}

Page JSP

 <div class="container-fluid">
    <div class="row">
          <c:choose>
            <c:when test="${!empty listaTodosProdutos}">
                <c:forEach items="${requestScope.listaTodosProdutos}" var="registro"> 


                    <div class="col-sm-6 col-md-6">
                      <img class="imagem_produto" src="<c:url value='/produto/imagens?descricao=${registro.codigo}'/>"/>

                    </div>

                    <div class="col-sm-6 col-md-6">
   <div class=""><c:out value = "${registro.descricao}"/></div>
     <div class=""><c:out value = "${registro.codigo}"/></div>              

                        <div class="linha_compra"></div><br/><br/>
                        </div>
  </c:forEach>  
   </c:when>
 </c:choose>

 <c:when test="${!empty listaParcela}">
    <c:forEach items="${requestScope.listaParcela}" var="registro"> 
                        <div class="col-sm-6 col-md-6">
                          <input name="valor" class="val" value="${registro.valor}" readonly="readonly"/>
                         </div>
                            <select id="parcelas" name="parcelas">
                                <option value="${registro.prod_parc1}">1x ${registro.prod_parc1}</option>
                                <option value="${registro.prod_parc2}">2x ${registro.prod_parc2}</option>
                                <option value="${registro.prod_parc3}">3x ${registro.prod_parc3}</option>
                                <option value="${registro.prod_parc4}">4x ${registro.prod_parc4}</option>
                                <option value="${registro.prod_parc5}">5x${registro.prod_parc5}</option>
                                <option value="${registro.prod_parc6}">6x${registro.prod_parc6}</option>
                                <option value="${registro.prod_parc7}">7x${registro.prod_parc7}</option>
                                <option value="${registro.prod_parc8}">8x${registro.prod_parc8}</option>
                                <option value="${registro.prod_parc9}">9x${registro.prod_parc9}</option>
                                <option value="${registro.prod_parc10}">10x${registro.prod_parc10}</option>
                            </select><br/><br/>
        </c:forEach>  
     </c:when>


             </div>
                    </div>
  • The error message indicates that all when can only be used as a child of choose. I believe that after the closing of the first choose you should have opened another one right away to print properly for when the parcel list is empty or not

  • as well in case I have to put the second <c:when> inside the Choose tag ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.