Problems using JSTL

4

I'm implementing a WEB application with J2EE, but I'm not able to list the data coming from the ServletListCourses to the Liste.Jsp page that uses JSTL.

  public class ServletListarCursos extends HttpServlet {  

    private static final long serialVersionUID=1L;  
    private static final String CONTENT_TYPE="text/html";  

    public void doPost(HttpServletRequest request, HttpServletResponse response)throws HTTPException, IOException{  

        response.setContentType(CONTENT_TYPE);  
        HttpSession session = request.getSession(true);  
        FachadaControladorDAO fachada = FachadaControladorDAO.getInstancia();  

        Curso curso = new Curso();  
        try {  
          List colecao =  fachada.getListarCursos(curso);  
          session.setAttribute("colecao", colecao);  

          RequestDispatcher rd = request.getRequestDispatcher("view/curso/ListaDeCursos.jsp");  
          rd.forward(request, response);  

        } catch (RepositorioException ex) {  
            Logger.getLogger(ServletListarCursos.class.getName()).log(Level.SEVERE, null, ex);  
        }catch(ServletException ex){  
            ex.printStackTrace();  
        }  

    }         

}  

The ServletListCourses sends the list of courses ("collection") to CourseList.jsp.

<%@page contentType="text/html" pageEncoding="UTF-8"%>  
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
    <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
        <title>Lista de cursos</title>  
         <select id="selecaoCursos" name="selecaoCursos"  >  
            <option value="0" >Selecione o curso</option>  
            <c:forEach items="${colecao}" var="cursos"  >  
               <option  value="${cursos.codigoCurso}"
                        id="codigoCurso">
                        ${cursos.nomeCurso}
               </option>  
            </c:forEach>  
         </select>  
    </body>  
</html>  

Doubt I can not list the DB values through the ServletListCourses, using JSTL.

    
asked by anonymous 11.02.2015 / 11:31

1 answer

4

Access the list in the correct scope, in your case the object was sent to the session:

session.setAttribute("colecao", colecao); 

In jsp call this:

 <c:forEach items="${sessionScope.colecao}" var="cursos"  >  

Or you can still use the scope of request

request.setAttribute("colecao", colecao); 

jsp

<c:forEach items="${colecao}" var="cursos"  > 
    
11.02.2015 / 11:55