spring和jfinal中在JSP頁面用EL表示式獲取資料
阿新 • • 發佈:2019-01-21
spring中在跳轉的jsp頁面中用EL表示式獲取資料時候,要加上isELIgnored="false",不然是不會解析EL表示式的,但是在就final就不需要
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>商品查詢頁面</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <form action="${pageContext.request.contextPath}/item/queryItem.action" method="post"> 查詢條件: <table width="100%" border="1px solid red"> <tr> <td><input type="submit" value="查詢"></td> </tr> </table> 商品列表: <table width="100%" border="1px solid red"> <tr> <td>序號</td> <td>商品名稱</td> <td>商品價格</td> <td>商品日期</td> <td>商品描述</td> <td>操作</td> </tr> <c:forEach items="${list}" var="item" varStatus="start"> <tr> <td>${start.index+1}</td> <td>${item.name}</td> <td>${item.price}</td> <td>${item.createtime}</td> <td>${item.detail}</td> <td><a href="${pageContext.request.contextPath}/item/editItem.action?id=${item.id}">修改</a></td> </tr> </c:forEach> </table> </form> </body> </html>
其中具體的取值如下:
<h4>獲取域物件中的值</h4>
<%request.setAttribute("name", "射鵰英雄傳");
application.setAttribute("name", "鹿鼎記");
%>
${requestScope.name }
${applicationScope.name }
<h4>獲取陣列中的值</h4>
<%
String [] strs={"陸小鳳","葉孤城","西門吹雪","李尋歡"};
request.setAttribute("strs", strs);
%>
${strs[1] }
<h4>獲取集合中的值</h4>
<%
List<String> list=new ArrayList<String>();
list.add("周芷若");
list.add("小昭");
list.add("趙敏");
list.add("蛛兒");
request.setAttribute("list", list);
%>
${list[2] }
<h4>獲取Map中的值</h4>
<%
Map<String,String> map=new HashMap<String,String>();
map.put("A", "東邪");
map.put("B", "西毒");
map.put("C", "南帝");
map.put("D", "北丐");
request.setAttribute("map", map);
%>
${map['B'] }
${map.C }
<h4>獲取集合中物件的值</h4>
<%
List<User2> uList=new ArrayList<User2>();
uList.add(new User2("劉備","147"));
uList.add(new User2("關羽","258"));
uList.add(new User2("張飛","369"));
request.setAttribute("uList", uList);
%>
${uList[1].username }
${uList[1].password }