表达式语言的集合操作

Servlet文件:

List <Dept>all=new ArrayList<Dept>();

Dept dept=null;

dept=new Dept();

 

dept.setDeptno(01);

dept.setDname("研发部");

dept.setLoc("办公楼二楼");

 

all.add(dept);

 

dept.setDeptno(02);

dept.setDname("销售部");

dept.setLoc("办公楼1楼");

 

all.add(dept);

 

request.setAttribuate("alldept",all);

request.getRequestDispatcher("dept_list.jsp").forward(requesr,response);//通过服务器跳转传递request属性

 

 

dept_list.jsp:

<body>

<%

  List all=(List) request.getAttribute("alldept");

  if(all!=null){

%>

  <table border="1" width="90%">

  <tr>

    <td>部门编号</td>

    <td>部门名称</td>

    <td>部门位置</td>

  </tr>

<%

  Iterator iter=all.iterator();

  while(iter.hasNext()){

pageContext.setAttribute("dept",iter.next));  

%>

    <tr>

        <td>${dept.deptno}</td>

        <td>${dept.dname}</td>

        <td>${dept.loc}</td>

    </TR>

<%

  }

%>

</table>

<%

}

%>

</body>

 

 

web.xml:

<servlet>

  <servlet-name>ELListServlet</servlet-name>

  <servlet-class>

    *.ELListServlet

  </servlet-class>

 

</servlet>

<servlet-mapping>

  <servlet-name>ELListServlet</servlet-name>

  <url-pattern>.....</url-pattern>

</servlet-mapping>

你可能感兴趣的:(表达式语言的集合操作)