JSTL和EL的区别

来源:互联网 发布:js隐藏tr 编辑:程序博客网 时间:2024/05/06 19:34

ELExpression Language(表达式语言)

EL的语法:${  EL exprission }

${  bean.name } 或  ${  bean['name'] }

说白了,EL是用来显示数据的,功能跟<%=表达式%> 一样,EL是不需要引入什么东西的

JSTLJavaServerPages Standard Tag LibraryJSP标准标签库

JSTL标准标签库包括核心标签库和SQL标签库,核心标签库常用的是ifforEach

说白了JSTL常实现网页逻辑判断和迭代显示的,需要引入

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

只要JSTLEL结合,就基本可以让页面再无<% %> 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>

可能说得不是很清楚,这个多查查资料,多练练手就会了

原创粉丝点击