EL
EL・・・Expression Languageの略で、式言語という意味。Beanやプロパティを取得する処理を、簡潔に記述できる。
<!-- 属性名.プロパティ名 --> <p>${product.id }:${product.name }:${product.price }</p>
ELでメソッドを呼び出す
${Math.random() }
リストやマップから要素を取り出すサンプル
<% int[] array = {0, 1, 2}; //ページ属性設定 request.setAttribute("array", array); List<String> list = new ArrayList(); list.add("zero"); list.add("one"); list.add("two"); // ページ属性設定 request.setAttribute("list", list); Map<String, String> map = new HashMap(); map.put("zero", "零"); map.put("one", "壱"); map.put("two", "弐"); //ページ属性設定 request.setAttribute("map", map); %> ${array[1]}<br> ${list[2] }<br> ${map["one"]}<br> ${map.two }
暗黙オブジェクトを使ったリクエストパラメータの取得サンプル
<form action="el5-2.jsp" method="post"> <input type="text" name="price"> 円× <input type="text" name="count"> 個= <input type="submit" value="計算">
<!-- 暗黙オブジェクト -->
${param.price }円×
${param.count }個=
${param.price*param.count}円
<!-- リクエストパラメータの取得 -->
${param.user }
${param.user.length() }
${param.user.toUpperCase() }