EL&&JSTL使用
来源:互联网 发布:淘宝天猫商家数量 编辑:程序博客网 时间:2024/06/02 01:11
EL标签
1.新建el.jsp
<%@pageimport="java.util.ArrayList"%>
<%@pageimport="java.util.List"%>
<%@pageimport="java.util.HashMap"%>
<%@pageimport="java.util.Map"%>
<%@pageimport="p1123.Books"%>
<%@ page language="java"contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Stringpath = request.getContextPath();
StringbasePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("ctx", basePath);
request.setAttribute("username","zhangsan_request");
session.setAttribute("username","zhangsan_session");
application.setAttribute("username","zhangsan_app");
Booksbooks = new Books();
books.setName("think in java");
pageContext.setAttribute("book", books);
Map names = newHashMap();
names.put("one","LiYang");
names.put("two","WangHua");
pageContext.setAttribute("names",names);
List ages = newArrayList();
ages.add(123);
ages.add(456);
pageContext.setAttribute("ages",ages);
%>
<!DOCTYPEhtmlPUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<basehref="<%=basePath%>">
<metahttp-equiv="Content-Type"content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>从不同范围取值</h3>
${ctx} <br>
${username}<br>
${applicationScope.username}<br>
复合对象的属性提取<br>
${book.name}=${book['name'] }
<h3>Map操作</h3>
${names['one']}
<h3>List/数组操作</h3>
${ages[1]}
<h3>el的范围前缀可以省略,可以是四个范围,还可以是:param/params</h3>
${param.name} = request.getParameter("name");
</body>
</html>
2.访问地址
http://localhost:8085/Practise/p1123/el.jsp?name=12
3.效果
JSTL标签
1.新建jstl.jsp
<%@ page language="java"contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglibprefix="c"uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPEhtmlPUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<basehref="<%=basePath%>">
<metahttp-equiv="Content-Type"content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
${param.age }
<%
int age = Integer.parseInt(request.getParameter("age"));
if(age>40)
out.print("中年");
else
out.print("青年");
%>
<h3>JSTL配合EL表达式将大大简化代码</h3>
<c:iftest="${param.age>50 }">
中年
</c:if>
<c:iftest="${param.age<50 }">
青年
</c:if>
<h3>通用标签</h3>
<c:setvar="example"value="${100+1}"scope="session" />
<c:outvalue="${example}"default="1000"/>==${example}
<c:setvar="example"value="《》&&&<>" scope="session" />
<c:outvalue="${example}"escapeXml="true"/>
<c:removevar="example"scope="session"/>
<h3>迭代标签</h3>
<%
String[] strArr = new String[]{"a","b","c","d"} ;
request.setAttribute("list", strArr);
%>
<tableborder="1">
<trstyle="">
<td>内容1</td>
<td>操作</td>
</tr>
<c:forEachitems="${list }"var="item"varStatus="status">
<tr
<c:iftest="${status.index%2==0}">style="background-color:red;"</c:if>>
<td>${item }</td>
<td>删除</td>
</tr>
</c:forEach>
</table>
</body>
</html>
2.访问地址
http://localhost:8085/Practise/p1123/jstl.jsp?age=12
3.效果
- el,jstl使用
- EL&&JSTL使用
- el jstl使用
- JSTL EL的使用
- JSTL和EL的使用
- el和jstl的使用
- EL&JSTL表达式语言使用
- JSP JSTL EL标签使用
- 【jstl&el】jstl和EL的区别和使用
- jstl+el
- el+JSTL
- el,jstl
- EL&JSTL
- el+jstl
- EL、JSTL
- jstl el <%%>
- EL JSTL
- jstl el
- 敏捷技能修炼之小舵板之三:代码未动,测试先行
- IDictionary<TKey,TValue>数据字典使用讲解
- error: Failed dependencies:
- sql优化
- 微软开源.NET Framework,实现跨平台
- EL&&JSTL使用
- ListView 的多选模式
- POJ 题目1679The Unique MST(判断最小生成树是否是唯一的)
- 第十三周项目1.5—插入数据到数组
- hdu4884 TIANKENG’s rice shop【模拟】
- 搭建LNMP发布ecshop系统及压测启用opcache缓存与否的情况
- ajax学习笔记
- 第13周项目4-数组的排序(3)
- NSString常用方法