用于解决Action中request.setAttribute(“list”,list)
由于我用的是struts框架,就拿整个项目介绍:
1.首先把jstl的两个常用包jstl.jar、standard.jar加载到环境中
2.Action代码:(整个过程不需要了解,这儿方法就是返回一个封装Students对象的list,然后request.setAttribute(“list”,list)起来)
public ActionForward selectStudent(Actionmapping mapping,ActionForm. form, HttpServletRequest request,HttpServletResponse response) { StudentForm. studentForm. = (StudentForm) form; DBConnection dbconn = new DBConnection(); Connection conn = dbconn.getConnection(); StudentServiceFactory serviceFactory = new StudentServiceFactory(); List list = serviceFactory.getStudentService().selectStudent(conn); request.setAttribute("list",list); try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } return mapping.findForward("show");}
3.show.jsp页面:
//这三句很重要 ">
查询结果如下:
ID 姓名 // items为list的一个迭代器,list为Action中传递过来的list,student为Student类对象 ${student.id }//输出student的id属性 ${student.name }//输出student的name属性 //id为自定义的名字,name为Action中传过来的list,type为实体类,包括完整路径,这里是vo.Student //name为逻辑名,和logic:iterate id="li"中的id对应,property为实体类中真正的属性 ">删除 返回
在JSP页面引入Struts标签库的时候有所不同:
struts1.3的为:
或者