学习内容:
1.EL语法
JSTL

一.EL语法

java Web第三章学习内容(EL语法及JSTL)

使用表达式可以快速获取session.setAttribute里面的值,不用再get出来

当遇到作用域的问题,可以在相应作用域下加Scope关键词获取:
如:    sessionScope.XXXX

java Web第三章学习内容(EL语法及JSTL)

二.JSTL

使用前先添加<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

使用fmt要添加<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

例:java Web第三章学习内容(EL语法及JSTL)

java Web第三章学习内容(EL语法及JSTL)

常用的forEach,forMatDate,其他很少使用


参考代码:
INDEX跳转MYJSP案例:

INDEX:


  <body>
    <%
    Student student = new Student(1,"哈哈");
    Student student2 = new Student(2,"呵呵");
    Student student3 = new Student(3,"嘻嘻");
    session.setAttribute("student1", student);
    
    List<Student> lists = new ArrayList<Student>();
   
    lists.add(student);
    lists.add(student2);
    lists.add(student3);
    session.setAttribute("student2", lists);
    response.sendRedirect("MyJsp.jsp");
    %>
    


  </body>

MYJSP参考代码:

<c:set var="a" value="asda"></c:set>
<%
Date date = new Date();
pageContext.setAttribute("time", date);


%>
<c:forEach var="item" items="${student2}"varStatus="num">
<table border=2>
<tr <c:if test="${num.count%2==0}">style="background-color: yellow" </c:if>>>
<td>${item.id}</td>
<td>${item.name}</td>


<%-- <c:out value="${item.name}"></c:out> --%>
</tr>
</table>
</c:forEach>
<fmt:formatDate value="${time}"pattern="yyyy-MM-dd HH:mm:ss"/>

相关文章:

  • 2021-11-10
  • 2021-04-03
  • 2021-12-13
  • 2021-05-18
  • 2021-05-27
  • 2021-07-26
  • 2021-08-15
  • 2021-08-26
猜你喜欢
  • 2021-11-12
  • 2021-06-22
  • 2022-01-01
  • 2021-09-10
  • 2021-06-23
  • 2021-09-13
  • 2022-01-23
相关资源
相似解决方案