jstl 与 el表达式
jar下载地址参考:https://blog.csdn.net/qq_30062589/article/details/80224080
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <c:if test="${empty users }"> aaa </c:if> <c:if test="${!empty users}"> bbb </c:if> <br> <c:forEach begin="0" end="5" var="i"> ${i }<br/> </c:forEach> <c:forEach items="${applicationScope.users }" var="user"> ${user.name }<br/> </c:forEach> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="cn.sasa.domain.*" %> <%@ page import="java.util.*" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% request.setAttribute("name", "hi"); MyUser user1 = new MyUser(); user1.setName("aaa"); session.setAttribute("user", user1); MyUser user2 = new MyUser(); user2.setName("bbb"); List<MyUser> userList = new ArrayList<MyUser>(); userList.add(user1); userList.add(user2); application.setAttribute("users", userList); out.write("web----"+this.getServletContext().getContextPath()); %> <!-- el表达式从域中取值取值 --> <br/> ${ requestScope.name } <br/> ${sessionScope.user.name } <br/> ${applicationScope.users[0].name } ${applicationScope.users[1].name } <hr/> <!-- *全域查找 --> <br/> ${ name } <br/> ${user.name } <br/> ${users[0].name } ${users[1].name } <br/> el_web_-----${pageContext.request.contextPath } </body> </html>