logic:iterate 里面的id和name寫什么,對應哪里

          <table bgcolor="#ff80ff" border="1">
             <tr>
            
             <th>工號</th>
             <th>姓名</th>
             <th>工作</th>
             <th>年限</th>
             <th>工資</th>
             </tr>
              <logic:iterate id="emp" name="list">    <td><bean:write name="emp" property="Empno"/></td>
              <td><bean:write name="emp" property="Ename"/></td>
               <td><bean:write name="emp" property="Job"/></td>
              <td><bean:write name="emp" property="Hiredate"/></td>
              <td><bean:write name="emp" property="Sal"/></td>   
              </logic:iterate>
            

           
             </table>

           
            </body>


          --------------------------------------------------------------------------------------------------


          public class QueryAction extends Action {

          public ActionForward execute(ActionMapping mapping, ActionForm form,
          HttpServletRequest request, HttpServletResponse response) {

          EmpDao empDao = new EmpDao();
          ArrayList list = empDao.empName();
          //System.out.println(list);
          request.setAttribute("list", list);

          return new ActionForward("/display.jsp");
          }
          }


          Java代碼 復制代碼
          1. <logic:iterate id="emp" name="list">   

          name屬性:是你放置Bean的集合,在你的這段代碼中:
          Java代碼 復制代碼
          1. public class QueryAction extends Action {    
          2.   
          3. public ActionForward execute(ActionMapping mapping, ActionForm form,    
          4. HttpServletRequest request, HttpServletResponse response) {    
          5.   
          6. EmpDao empDao = new EmpDao();    
          7. ArrayList list = empDao.empName();    
          8. //System.out.println(list);    
          9. request.setAttribute("list", list);    
          10.   
          11. return new ActionForward("/display.jsp");    
          12. }    
          13. }   

          Java代碼 復制代碼
          1. request.setAttribute("list", list);  
          你是將list放入到request范圍內,對應的名字是list,如果你要是寫成
          Java代碼 復制代碼
          1. request.setAttribute("myList", list);  
          ,那么,logic:iterator中的name屬性就要為"myList".
          logic:iterator中的id屬性,其實是你要從你的集合中取出的Bean的名字,這個名字是任意起的,主要是下面的<bean:write name="emp" property="Ename"/>標簽中的name屬性要跟logic:iterator中的id屬性對應上.其實這里的是這樣的,首先<logic:iterator>標簽會把name屬性值為list的集合里的bean逐一取出來,每取出來一個,就把他存到名為id屬性的值的pageContext范圍內,一看代碼你就能明白:
          主要代碼:
          Java代碼 復制代碼
          1. //首先取出List,getAttribute()方法中的值就是<logic:iterator>標簽的name   
          2. //值   
          3. List list=request.getAttribute("list");   
          4. //然后把取出來的bean存入pageContext范圍內,對應的名字就是id的值   
          5. pageContext.setAttribute("emp",bean);   
          6. //<bean:write>標簽其實就是利用反射把Bean從相應的范圍內取出   
          7. pageContext.getAttribute("emp");  

          posted on 2009-04-13 11:53 MichaelLee 閱讀(1788) 評論(0)  編輯  收藏 所屬分類: Struts


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          公告

          ====Michael Lee====
          =Java Sofware Engineer=
          =Work @ Beijing=
          ---再煩,也別忘微笑;再急,也要注意語氣;再苦,也別忘堅持;再累,也要愛自己!---
          ---低調做人,你會一次比一次穩健;高調做事,你會一次比一次優秀---
          ---成功的時候不要忘記過去;失敗的時候不要忘記還有未來---

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 曲阜市| 祥云县| 景谷| 会东县| 赤峰市| 六安市| 新野县| 广元市| 海口市| 凤凰县| 罗山县| 高邮市| 绥芬河市| 乐安县| 井冈山市| 辽中县| 瑞丽市| 阿鲁科尔沁旗| 松原市| 临潭县| 湖口县| 中超| 休宁县| 西乡县| 太原市| 原阳县| 博罗县| 澄江县| 温宿县| 平定县| 乐亭县| 沁源县| 锦州市| 宁阳县| 鹤壁市| 高邮市| 云林县| 南川市| 集贤县| 黔南| 增城市|