国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

使用JSTL標簽來訪問list并判斷l(xiāng)ist中的選中項

2024-07-21 02:15:11
字體:
供稿:網(wǎng)友

  本文將向大家講述如何通過sun公司的jstl標簽來訪問list對象,并在jsp頁面進行顯示

  一般而言,list對象會存儲在request對象,session對象中,一般采用框架(比如說struts框架中的action)完成把list對象置入request對象中,

xxaction{

public actionforward execute(
  actionmapping mapping,
  actionform form,
  httpservletrequest request,
  httpservletresponse response) {

/*從session中獲得用戶信息*/

httpsession session=request.getsession();
  user user =(user)session.getattribute("user");
  request.setattribute("user",user);

/*建立rolelist*/

list rolelist =new arraylist();
  for(int i=0;i<5;i++){
   role role= new role(i,"role"+i);
   rolelist.add(role);
  }

request.setattribute("role_list",rolelist);

}

  本文的講解重點是jstl標簽部分:

<%@ taglib uri="/jstl/core" prefix="c"%>

<c:set var="user" value="${user}" />

<tr bgcolor="#ffffff">
      <td align="center" valign="top">

<!--

  因為涉及到中文字符問題,所以通過使用struts標簽來讀者資源文件中的adduser.role項,對應的中文編碼為:角色-->

<bean:message key="adduser.role" /></td>
      <td>
       <select name="role">
       <c:foreach var="ro" items="${role_list}"><!--訪問request中的role_list對象-->
        <c:choose>
         <c:when test="${user.role==ro.role_name}"><!--判斷,相當于if(user.getrole().equlas(rolgetrolename()))假如user中的role和list中的role相同就在select中選中(高亮)-->

          <option selected="selected"
           value="<c:out value="${ro.role_id}"/>"><!--設定value項,這樣保證頁面中看到的是name,當選中

以后,傳到接受端實際為id-->
           <c:out value="${ro.role_name}"/><!--看到的是role_name-->
           </option>
         </c:when>
         <c:otherwise><!--相當于else-->
          <option value="<c:out value="${ro.role_id}"/>"><!--原理同上-->
          <c:out
           value="${ro.role_name}"></c:out></option>
         </c:otherwise>
        </c:choose>
       </c:foreach><!--循環(huán)end-->

      </select></td>
     </tr>

  共勉,歡迎交流:[email protected]



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 久治县| 霞浦县| 阿克苏市| 苍山县| 铅山县| 庐江县| 象山县| 纳雍县| 和顺县| 教育| 绍兴县| 南城县| 缙云县| 东海县| 锡林郭勒盟| 荔浦县| 泸水县| 东源县| 元阳县| 什邡市| 镇江市| 石河子市| 申扎县| 香港 | 庆云县| 通渭县| 黔西| 岳西县| 莱州市| 博野县| 浪卡子县| 武义县| 双峰县| 观塘区| 泰安市| 潞西市| 涡阳县| 丹凤县| 平武县| 平定县| 普安县|