我设置了一个查找对应年份显示数据库内容的类,运行时显示items无法进行遍历是为什么,是不代码写得哪里有问题
public User selectUserBynian(String nian) { // 根据年进行查询
Connection conn = DbDao.getConnection();
String sql = "select * from user where nian = " + nian;
User user = null;
try {
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rst = pst.executeQuery();
while (rst.next()) {
user = new User();
user.setNian(rst.getString("nian"));
user.setId(rst.getInt("id"));
user.setname(rst.getString("name"));
user.setId_card(rst.getString("id_card"));
user.setId_dianzi(rst.getString("id_dianzi"));
user.setState(rst.getString("state"));
user.setYue(rst.getString("yue"));
user.setRi(rst.getString("ri"));
}
rst.close();
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
return user; // 返回
}
public class NianServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
SimpleDateFormat df = new SimpleDateFormat("yyyy");
String nian = df.format(new Date());
UserDao dao = new UserDao();
User user = dao.selectUserBynian(nian);
req.setAttribute("nian", user);
req.getRequestDispatcher("/nianshow.jsp").forward(req, resp);
}
}
<c:forEach var="N" items="${nian}" >
<tr>
<td><input type="text" value="${N.id}" name="id" ></td>
<td><input type="text" value="${N.name}" name="name"></td>
<td><input type="text" value="${N.id_card}" name="idcard"></td>
<td><input type="text" value="${N.id_dianzi}" name="id_dianzi"></td>
<td><input type="text" value="${N.state}" name="state"></td>
<td><input type="text" value="${N.nian}" name="nian"></td>
<td><input type="text" value="${N.yue}" name="yue"></td>
<td><input type="text" value="${N.ri}" name="ri"></td>
</tr>
</c:forEach>
错误说Don't know how to iterate over supplied "items" in <forEach>