1、EL表達式
獲取4個內置對象(域)中的數據,或自定義對象中的數據,或數組、集合容器中的數據。可以完成非常簡單的運行,但它不能完成循環、復雜的判斷等功能。
EL表達式的書寫格式:${ 表達式 }
2、獲取變量數據
<%
String name="陶士涵";
pageContext.setAttribute("name",name);
%>
取值的方式:${name}
3、獲取數組數據
<%
String[] names={"陶士涵","張三"};
pageContext.setAttribute("names",names);
%>
取值的方式:${name[0]}
4、獲取集合數據
<%
List<String> names=new ArrayList<String>();
names.add("陶士涵");
names.add("張三");
pageContext.setAttribute("names",names);
%>
取值的方式:${names[1]}
<%
Map<String,String> names=new HashMap<String,String>();
names.put("name","陶士涵");
pageContext.setAttribute("names",names);
%>
取值的方式:${names['name']} ${names.name }
5、獲取javabean數據
<%
Person person=new Person();
person.setName("taoshihan");
pageContext.setAttribute("person",person);
%>
取值的方式:${person.name }
例如:通過bsp獲取當前登錄人名稱與試卷創建人名稱是否一致:
<%
String path = request.getContextPath();
String userName = BspUtil.getInstance().getLoginUserName();
pageContext.setAttribute("userName",userName);
%>
<c:when test="${question.creator == userName}">
<button class="btn btn-danger" id="delete-question-btn">
<i class="fa fa-trash-o"></i> 刪除該題
</button>
<button class="btn btn-info" onclick="javascript:window.close();">
<i class="fa fa-times"></i> 關閉頁面
</button>
</c:when>
