JSTL和EL的区别

来源:互联网 发布:家庭网络布线方案 编辑:程序博客网 时间:2024/05/19 14:53
JSTL(JSP Standard Tag Library,JSP标准标签库)是一个不断完善的开放源代码的JSP标签库,是由apache的jakarta小组来维护的。JSTL只能运行在支持JSP1.2和Servlet2.3规范的容器上,如tomcat 4.x。在JSP 2.0中也是作为标准支持的。JSTL(JavaServerPages Standard Tag Library)JSP标准标签库JSTL标准标签库包括核心标签库和SQL标签库,核心标签库常用的是if和forEachEL即Expression Language(表达式语言)EL的语法:${  EL exprission }${  bean.name } 或  ${  bean['name'] }说白了,EL是用来显示数据的,功能跟<%=表达式%> 一样,EL是不需要引入什么东西的
EL即Expression Language(表达式语言)
EL的语法:${ EL exprission }
${ bean.name } 或 ${ bean['name'] }
说白了,EL是用来显示数据的,功能跟<%=表达式%> 一样,EL是不需要引入什么东西的

JSTL(JavaServerPages Standard Tag Library)JSP标准标签库
JSTL标准标签库包括核心标签库和SQL标签库,核心标签库常用的是if和forEach
说白了JSTL常实现网页逻辑判断和迭代显示的,需要引入
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
只要JSTL和EL结合,就基本可以让页面再无<% %> jsp代码了。
给你一段我今天考试的代码:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</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="work.do?method=search" method="post">
<table border="1" align="center" width="50%">
班级:<select name="student.s_class">
<option value="0">全部</option>
<c:forEach var="T_class" items="${requestScope.tClassList}">
<option value="${T_class.c_no}">
${T_class.c_name}
</option>
</c:forEach>
</select>
科目:<select name="student.s_schedule">
<option value="0">全部</option>
<c:forEach var="T_schedule" items="${requestScope.tSchedultList}">
<option value="${T_schedule.s_no}">
${T_schedule.s_name}
</option>
</c:forEach>
</select>
状态<select name="student.s_status">
<option value="0">全部</option>
<option value="1">已处理</option>
<option value="2">未处理</option>
</select>
<input type="submit" value="提交">
</table>
</form>

<c:if test="${requestScope.searchResult==0}">
<h5 align=center>无此数据</h5>
</c:if>

<c:if test="${requestScope.searchResult==1}">
<h3 align=center>查询结果如下</h3>
<table border="1" align="center" width="50%">
<tr>
<th>姓名</th>
<th>班级</th>
<th>科目</th>
<th>成绩/处理</th>
</tr>
<c:forEach var="MainBean" items="${requestScope.mainList}">
<tr>
<td>${MainBean.s_name}</td>
<td>${MainBean.c_name}</td>
<td>${MainBean.ts_name}</td>
<td>
<c:if test="${MainBean.s_status==1}">${MainBean.s_score}</c:if>
<c:if test="${MainBean.s_status==2}"><a href="work.do?method=toPiyue&stuId=${MainBean.id}">批阅</a></c:if>
</td>
</tr>
</c:forEach>
</table></c:if>
</body>
</html>
0 0
原创粉丝点击