一、EL
表达式的 11 个隐含对象
二、EL
获取四个特定域中的属性
<body>
<%
pageContext.setAttribute("key1", "pageContext1");
pageContext.setAttribute("key2", "pageContext2");
request.setAttribute("key2", "request");
session.setAttribute("key2", "session");
application.setAttribute("key2", "application");
%>
${pageScope.key1}
${requestScope.key2}
${sessionScope.key2}
${applicationScope.key2}
</body>
三、pageContext
对象的使用
<%--jsp的方法--%>
<%=request.getScheme()%>
<%=request.getServerName()%>
<%=request.getServerPort()%>
<%=request.getContextPath()%>
<%=request.getMethod()%>
<%=request.getRemoteHost()%>
<%=session.getId()%>
<%--EL的方法 --%>
<%--1. 协议: --%>
${pageContext.request.scheme}
<%--2. 服务器 ip: --%>
${pageContext.request.serverName}
<%--3. 服务器端口: --%>
${pageContext.request.serverPort}
<%--4. 获取工程路径: --%>
${pageContext.request.contextPath}
<%--5. 获取请求方法: --%>
${pageContext.request.method}
<%--6. 获取客户端 ip 地址: --%>
${pageContext.request.remoteHost}
<%--7. 获取会话的 id 编号:--%>
${pageContext.session.id}
四、EL
表达式其他隐含对象的使用
输出请求参数 username 的值:${ param.username }
输出请求参数 password 的值:${ param.password }
输出请求参数 username 的值:${ paramValues.username[0] }
输出请求参数 hobby 的值:${ paramValues.hobby[0] }
输出请求参数 hobby 的值:${ paramValues.hobby[1] }
输出请求头【User-Agent】的值:${ header['User-Agent'] }
输出请求头【Connection】的值:${ header.Connection }
输出请求头【User-Agent】的值:${ headerValues['User-Agent'][0] }
获取 Cookie 的名称:${ cookie.JSESSIONID.name }
获取 Cookie 的值:${ cookie.JSESSIONID.value }