首页 文章

jsp servlet中的ArrayList null

提问于
浏览
0

我的ArrayList为null,为什么?

JSP

<jsp:include page="/ServletCargaEstacionamiento"></jsp:include>
    <% ArrayList<Estacionamiento> estacionamientos = (ArrayList <Estacionamiento >) request.getSession().getAttribute("est"); %>

ServletCargaEstacionamiento.java

DAOEstacionamiento daoe = new DAOEstacionamiento();
    ArrayList<Estacionamiento> estacionamientos = daoe.select();
    request.getSession().setAttribute("est", estacionamientos);

DAOEstacionamiento

while(rs.next()){
            estacionamientos.add(new Estacionamiento(rs.getInt("idEstacionamiento"), rs.getString("lugar")));}

1 回答

  • 0

    通过与 web.xml 中的 <url-pattern> 匹配的URL调用Servlet,例如 http://example.com/contextname/ServletCargaEstacionamiento .

    您调用servlet,然后转发到JSP以显示结果 . 创建一个Servlet,它在 doGet() 方法中执行类似的操作 .

    DAOEstacionamiento daoe = new DAOEstacionamiento();
    ArrayList<Estacionamiento> estacionamientos = daoe.select();
    request.getSession().setAttribute("est", estacionamientos);
    request.getRequestDispatcher("/WEB-INF/result.jsp").forward(request, response);
    

    并在 /WEB-INF/result.jsp

    <% ArrayList<Estacionamiento> estacionamientos = (ArrayList <Estacionamiento >) request.getSession().getAttribute("est"); %>
    

相关问题