EL表達式和代碼片斷互相取值

<c:set var="companyName" value="${companymap['company']}" scope="request"></c:set>spa

將el表達式的值setAttribute中,而後就能夠在代碼中直接使用companyName變量code

EL表達式取片斷值:orm

將代碼片斷中的屬性或者集合setAttribute中,而後在頁面EL表達式中獲取${**}獲取就行get

片斷取EL表達式值:it

request.getAttribute("companyName") == EL表達式${companyName} io

eg:form

//獲取後臺傳過來的集合,取出其中重複的公司名稱的項,並將(公司名,出現次數)放入map中,而後再存入頁面中。
List<Map<String,String>> companyinformationLists = (List<Map<String,String>>)request.getAttribute("companyinfoLists");
Map<String, Integer> map = new HashMap<String, Integer>();
if(companyinformationLists != null){
	for(int i = 0; i < companyinformationLists.size(); i++){
		if(!map.containsKey(companyinformationLists.get(i).get("company"))){
	map.put(companyinformationLists.get(i).get("company"),1);
		}else{
	map.put(companyinformationLists.get(i).get("company"),1+map.get(companyinformationLists.get(i).get("company")));
		}
	}
	request.setAttribute("map",map);
}


<c:forEach var="companymap" items="${companyinfoLists}" varStatus="companynum">
<c:choose>
<c:when test="${map[companymap['company']] > 1}">
<tr>
  <c:set var="companyName" value="${companymap['company']}" scope="request"></c:set>
  <td width="22%" rowspan="${map[companymap['company']]}">${companymap['company']}</td>
  <td width="8%">${companymap['month']}</td>
  <td width="15%" rowspan="${map[companymap['company']]}">${companymap['agreementsystem']}</td>
相關文章
相關標籤/搜索