jsp el的内置对象

一、el内置对象(11个):

  pageScope (掌握)

  requestScope (掌握)

  applicationScope (掌握)

  sessionScope (掌握)

  param  (了解)

  paramValues  (了解)

  header  (了解)

  headerValues  (了解)

  initParam  (了解)

  cookie  (掌握)

  pageContext  (掌握)

注意:除了pageContext,其他都是map集合。

了解: 和参数相关的el内置对象:

    parma

    parmValues

<a href="action/demo1.jsp?username=evil&fava=eat">el内置对象参数相关</a>
 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <html>
 3 <head>
 4     <title>Title</title>
 5 </head>
 6 <body>
 7 ${param.fava}
 8 ${param.username}
 9 </body>
10 </html>

了解:和请求头相关的el内置对象。

    header

    headerValues

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <html>
 3 <head>
 4     <title>Title</title>
 5 </head>
 6 <body>
 7 ${header.referer}
 8 
 9 <% String refer=request.getHeader("referer");
10 request.setAttribute("refer",refer);
11 %>
12 ${refer}
13 </body>
14 </html>

了解:和全局初始化参数先关的el内置对象

    initParam

1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
2 <html>
3 <head>
4     <title>Title</title>
5 </head>
6 <body>
7 ${initParam.ok}
8 </body>
9 </html>
1     <context-param>
2         <param-name>ok</param-name>
3         <param-value>123</param-value>
4     </context-param>

掌握:   cookie内置对象:

 1)

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <html>
 3 <head>
 4     <title>Title</title>
 5 </head>
 6 <body>
 7 <%
 8 Cookie cookie=new Cookie("username","evil");
 9 response.addCookie(cookie);
10 %>
11 ${cookie}
12 <br>
13 ${cookie.username.name}<br>
14 ${cookie.username.value}<br>
15 </body>
16 </html>

  

从上面的结果,可以看出来,我们定义的cookie,在el cookie对象的是由我们定义键=new Cookie("username","evil")

我们在获取cookie的键和值的时候,是通过方法,getName()和getValue()

所以name和value是el对象cookie的 bean属性。于是获取的格式如下:

格式:

${cookie.设置的键名字.name} 获取cookie的键名字。

${cookie.设置的键名字.value} 获取cookie的value。

也就是说,在el表达式中我们可以通过符合javabean方式的,通过属性(.)获取对应的值。

二、jsp的注释:

<%-- --%>

原文地址:https://www.cnblogs.com/evilliu/p/8624949.html