[英]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.