DataBase db=new DataBase();
List listRes = new LinkedList();
ResultSet rs=db.executeQuery(sql);
try{while(rs.next()){
hotel bean = new hotel();
bean .setHotelid(rs.getString("hotelid"));
bean.setHotelname(rs.getString("hotelname"));
bean.setHoteldetail(rs.getString("hoteldetail"));
bean.setCount(rs.getInt("count"));
bean.setAddress(rs.getString("address"));
bean.setPicture(rs.getString("picture"));
bean.setType(rs.getString("type"));
listRes.add(bean);
}
HttpSession session=request.getSession();
session.setAttribute("listRes", listRes);
这个在输出的SQL语句查询有结果但是我在jsp页面用
Array dataList = (Array)request.getAttribute("listRes");
取到的dataList是空值!为什么?
------解决方案--------------------
HttpSession session=request.getSession();
session.setAttribute("listRes", listRes);
你的问题一:你存入session肯定从session里取噻,怎么用request.getAttribute()哦?(主要原因)
问题二:上面用LinkedList,JSP中怎么又用Array?
------解决方案--------------------
DataBase db=new DataBase();
List listRes = new LinkedList();
ResultSet rs=db.executeQuery(sql);
try{while(rs.next()){
hotel bean = new hotel();
bean .setHotelid(rs.getString("hotelid"));
bean.setHotelname(rs.getString("hotelname"));
bean.setHoteldetail(rs.getString("hoteldetail"));
bean.setCount(rs.getInt("count"));
bean.setAddress(rs.getString("address"));
bean.setPicture(rs.getString("picture"));
bean.setType(rs.getString("type"));
listRes.add(bean);
}
HttpSession session=request.getSession();
session.setAttribute("listRes", listRes);
这个在输出的SQL语句查询有结果但是我在jsp页面用
java.util.List dataList = (java.util.List)session.getAttribute("listRes");
试试看。........
------解决方案--------------------
不会哦``这么简单的问题还没解决啊
HttpSession session=request.getSession();
session.setAttribute("listRes", listRes);
System.out.println("长度=============="+listRes.length);你首先要确定查询出的结果集有数据没得噻``
在JSP中
<%
List list = (List)session.getAttribute("listRes");
for(int i = 0;i < list.size();i++){
hotel bean = (hotel)list.get(i);
}
%>