Java后端_EL表达式

记录课堂EL的知识点。

Expression Language,EL的全称。

EL有11个内置对象,与JSP九个内置对象一样。

重点的四个:

pageScope:从page范围域属性空间中查找指定的key
requestScope:从request范围域属性空间中查找指定的key
sessionScope:从session范围域属性空间中查找指定的key
applicationScope:从application范围域属性空间中查找指定的key

还有其他重要的对象,比如pageContext,param等等。

其中pageContext.request.contextPath是取出部署的应用程序名,这样不管如何部署,所用路径都是正确的。

案例:

一.

scopes.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
     <% pageContext.setAttribute("username","itcast");%>
     <% request.setAttribute("bookname","Java web");%>
     <% session.setAttribute("username","itheima");%>
     <% application.setAttribute("bookname","java");%>
         表达式\${pageScope.username}的值为:${pageScope.username} <br />
         表达式\${requestScope.bookname}的值为:${requestScope.bookname} <br />
         表达式\${sessionScope.username}的值为:${sessionScope.username} <br />
         表达式\${applicationScope.bookname}的值为:${applicationScope.bookname} <br />
         表达式\${username}的值为:${username}
</body>
</html>

使用EL表达式来获取四个域的值。

结果:

表达式 p a g e S c o p e . u s e r n a m e 的 值 为 : i t c a s t 表 达 式 {pageScope.username}的值为:itcast 表达式 pageScope.username:itcast{requestScope.bookname}的值为:Java
web 表达式 s e s s i o n S c o p e . u s e r n a m e 的 值 为 : i t h e i m a 表 达 式 {sessionScope.username}的值为:itheima 表达式 sessionScope.username:itheima{applicationScope.bookname}的值为:java 表达式${username}的值为:itcast

二.

param.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body style = "text-align:center;">
     <form action = "${pageContext.request.contextPath}/param.jsp">
          num1:<input type = "text" name = "num1"><br />
          num2:<input type = "text" name = "num"><br />
          num3:<input type = "text" name = "num"><br />
          <input type = "submit" value = "提交">&nbsp;&nbsp;
          <input type = "submit" value = "重置"><hr />
          num1: ${param.num1}<br />
          num2: ${paramValues.num[0]}<br />
          num3: ${paramValues.num[1]}<br />
     </form>
</body>
</html>

结果:

num1: 10
num2: 20
num3: 30


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BeJav

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值