EL 隐式对象
- pageContext
- 请求参数:${pageContext.request.queryString}
- 绝对路径:${pageContext.request.requestURL}:http://localhost/jstl/pages/MyJsp.jsp
- 工程名(相对路径):${pageContext.request.contextPath}:/jstl
- 请求方法:${pageContext.request.method}:GET
- HTTP版本:${pageContext.request.protocol}:HTTP/1.1
- ${pageContext.request.remoteUser}:
- IP地址:${pageContext.request.remoteAddr }:127.0.0.1
- session状态:${pageContext.session.new}:true
- session编号:${pageContext.session.id}:00EB0C78103D46152844178CCEAABA2E
- 请求参数
- 表达式 ${param.name} 相当于 request.getParameter (name)
- 表达式 ${paramvalues.name) 相当于 request.getParamterValues(name)
- 请求头
- 表达式 ${header.name} 相当于 request.getHeader(name)
- 表达式 ${headerValues.name} 相当于 request.getHeaderValues(name)
- Cookie
- 表达式 ${cookie.name.value} 返回带有特定名称的第一个 cookie 值
- 初始化参数
- ${initParam . name} name 是你在web.xml 文件中配置的初始化参数
- 将上下文初始化参数名称映射到单个值(通过调用 ServletContext.getInitparameter(String name) 获得)
-
requestScope
-
在页面请求时将javaBean一起传递
-
只在使用<jsp:forward> 时有效,当页面使用sendRedirect时不会传递
- 变量
- 任何出现在EL 表达式中的变量(除了上面的内置对象),都会被容器认为是在引用存储在某个作用域中的对象,可以这样认为,变量是某个作用域的属性,当EL 中出现了一个变量时,EL将到作用域中去找与它同名的属性,然后将值映射给变量EL语言中的变量与其他语言中的变量的权限和作用是不一样的
- EL 中的变量是不能够赋予新值的
- EL中的变量只能与某一个作用域相关联
- 将会在作用域中查找,顺序是: pageScope,requestScope,sessionScope,applicationScope
JSTL 实现的浏览器判断
<%@page pageEncoding="UTF-8" contentType="text/html"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>jsp page</title>
</head>
<body>
<c:choose>
<c:when test="${fn:contains(header['User-Agent'],'IE')}"> IE</c:when>
<c:otherwise>Not IE</c:otherwise>
</c:choose>
</body>
</html>

浙公网安备 33010602011771号