我的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 回答
通过与
web.xml
中的<url-pattern>
匹配的URL调用Servlet,例如http://example.com/contextname/ServletCargaEstacionamiento
.您调用servlet,然后转发到JSP以显示结果 . 创建一个Servlet,它在
doGet()
方法中执行类似的操作 .并在
/WEB-INF/result.jsp