spring和jfinal中在JSP页面用EL表达式获取数据

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 }

猜你喜欢

转载自blog.csdn.net/itxiaobaibai/article/details/80713001
今日推荐