日期:2014-05-18  浏览次数:20717 次

调用数据库数据显示在jsp页面上。为null。
根据typeid来检索数据库里的信息,在页面上显示typeid=1的内容,但是在页面上显示的是Null,求指导,如何正确的显示数据里的信息。
dao:
public interface InformationDao {
public List<Information>searchInformation(int typeid)throws SQLException;
daoimpl:
public class InformationDaoImpl implements InformationDao {

@Override
public List<Information> searchInformation(int typeid) throws SQLException {
String sql="select * from information where typeid=?";
List<Information>list=new ArrayList<Information>();
PreparedStatement pstmt=null;
ResultSet rs=null;
Connection conn=ConnDB.getConnection();
try {
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1, typeid);
rs=pstmt.executeQuery();
while (rs.next()) {
Information information=new Information();
information.setInformationid(rs.getRow());
information.setTitle(rs.getString("title"));
information.setContent(rs.getString("content"));
information.setTypeid(rs.getInt("typeid"));
information.setDate(rs.getString("date"));
list.add(information);


}
rs.close();
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}

}
jsp:
     <%
     String path = request.getContextPath();
        String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <%
request.setCharacterEncoding("utf-8");
String htmlData = request.getParameter("content")!=null?request.getParameter("content"):"";
%>
<%


int typeid=1;
InformationDaoImpl inf=new InformationDaoImpl();

List<Information> list=inf.searchInformation(typeid);
System.out.println("-----"+list.size());
%>


<div id="b">
<%
Iterator<Information>it=list.iterator();
while(it.hasNext()){
Information information=new Information();
int informationidString =information.getInformationid();
String titleString=information.getTitle();
String contentString=information.getContent();
int typeidString =information.getTypeid();
String datesString=information.getDate();
%>
<li><%=contentString%></li>
<%
}
%>
</div>
JEE JSP