繁体   English   中英

jsList servlet中的ArrayList为null

[英]ArrayList null in jsp servlet

我的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")));}

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

您调用servlet,然后该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"); %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM