Java Web之EL

<%--
  Created by IntelliJ IDEA.
  User: Vae
  Date: 2019/1/2
  Time: 12:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<p>许嵩许嵩</p>

<%
    //JSP的四大作用域
    pageContext.setAttribute("msg","pageContext");
    request.setAttribute("msg","request");
    session.setAttribute("msg","session");
    application.setAttribute("msg","application");
%>

<h3>获取每一个作用域中的值</h3>
pageContext:<%=pageContext.getAttribute("msg")%><br>
request:<%=request.getAttribute("msg")%><br>
session:<%=session.getAttribute("msg")%><br>
application:<%=application.getAttribute("msg")%><br>

<hr>
<h3>pageContext的findAttribute方法(只有pageContext才有)</h3>
<%=pageContext.findAttribute("msg")%><br>
<%=pageContext.findAttribute("msg")==null?"":pageContext.findAttribute("msg")%><br>
${msg}<br>

</body>
</html>

猜你喜欢

转载自www.cnblogs.com/yunquan/p/10241753.html