解决了你就是高手``servlet set的参数jsp接收不到``各位高手帮忙看下`纠结了很久了`
我在servlet set了个数组想让它的元素在jsp的下拉表框显示,可是jsp没得到想要的结果``
servlet:
request.setAttribute("noticeList", DaoFactory.getNoticeDaoInstance().find(key,recordStart,recordEnd));
=============================================================================================
jsp:
<c:forEach var="notice" items="${noticeList}">
<tr>
<td align="center"><c:out value="${notice.title}"></c:out></td>
=====================================================================================
find():
public List<Notice> find(String key,int recordStart,int recordEnd) {
List<Notice> list=new ArrayList<Notice>();
if(conn!=null){
StringBuffer sb=new StringBuffer("select * from tb_notices where 1=1");
if(key!=null&&!"".equals(key)){
sb.append(" and title like '%"+key+"%' or content like '%%"+key+"'");
}
if(recordStart!=-1){
sb.append(" and rownum>="+recordStart);
}
if(recordEnd!=-1){
sb.append(" anf rownum<="+recordEnd);
}
PreparedStatement pstmt=null;
ResultSet rs=null;
try{
pstmt=conn.prepareStatement(sb.toString());
rs=pstmt.executeQuery();
if(rs.next()){
Notice notice=new Notice();
notice.setContent(rs.getString("content"));
notice.setInTime(rs.getString("inTime"));
notice.setnId(rs.getInt("nId"));
notice.setTitle(rs.getString("title"));
list.add(notice);
}
=============================================================================================
ps:DaoFactory.getNoticeDaoInstance().find(key,recordStart,recordEnd);这个方法是取到参数了的,我在jsp试了下:
<%
List list=DaoFactory.getNoticeDaoInstance().find(key,recordStart,recordEnd);
System.out.println(list.size());
%>
这样输出的是1,好奇怪``数据库这边的数据明明就有10条,可只能取到一条``问题出在哪了?而且把
<%
request.setAttribute(“noticeList”,DaoFactory.getNoticeDaoInstance().find(key,recordStart,recordEnd));
%>
放到jsp,这样jstl显示代码不变下拉表框也是只显示数据库的第一条数据。。据我推测`问题是servlet set的参数根本传不来,还有find()那有问题,或许显示也有问题。各位`帮下忙啊``如果解决了 感激不尽 谢谢~!
------解决方案--------------------
Java code
if(rs.next()){// if 改成while就OK了