jsp表达式语言_JSP表达语言

JSP表达式语言(EL)旨在创建无脚本的JSP页面。EL表达式可用于标准和自定义标签的属性值,以及设置bean属性。在JSP中,有若干隐式对象可供使用,如request、session等。EL支持算术运算、逻辑运算和关系运算符。通过示例展示了EL如何简化JSP中的变量输出和操作。
摘要由CSDN通过智能技术生成

jsp表达式语言

Expression Language(EL) was added to JSP 2.0 specification. The purpose of EL is to produce scriptless JSP pages. The syntax of EL in a JSP is as follows:

表达式语言(EL)已添加到JSP 2.0规范中。 EL的目的是产生无脚本的JSP页面。 JSP中EL的语法如下:

${expr}

Here expr is a valid EL expression. An expression can be mixed with static text/values and can also be combined with other expressions to form larger expression.

这里expr是有效的EL表达式。 表达式可以与静态文本/值混合,也可以与其他表达式组合以形成更大的表达式。

expression language example

EL表达式如何使用? (How EL expression is used?)

EL expression can be used in two ways in a JSP page

在JSP页面中可以两种方式使用EL表达式

  1. As attribute values in standard and custom tags. Example:

    作为标准和自定义标签中的属性值。 例:

    <jsp:include page="${location}">

    Where location variable is separately defines in the jsp page.

    在jsp页面中分别定义位置变量的位置。

    Expressions can also be used in jsp:setProperty to set a properties value, using other bean properties like : If we have a bean named Square with properties length, breadth and area.

    也可以在jsp:setProperty使用表达式来设置属性值,并使用其他bean属性,例如:如果我们有一个名为Square的bean,其属性为length,breadth和area。

    <jsp:setProperty name="square" property="area" value="${square.length*square.breadth}" />
  2. To output in HTML tag:

    要以HTML标签输出:

    <h1>Welcome ${name}</h1>

To deactivate the evaluation of EL expressions, we specify the isELIgnored attribute of the page directive as below:

要停用EL表达式的求值,我们指定page指令的isELIgnored属性,如下所示:

<%@ page isELIgnored ="true|false" %>

JSP EL隐式对象 (JSP EL Implicit Objects)

Following are the implicit objects in EL :

以下是EL中的隐式对象:

Implicit ObjectDescription
pageContextIt represents the PageContext object.
pageScopeIt is used to access the value of any variable which is set in the Page scope
requestScopeIt is used to access the value of any variable which is set in the Request scope.
sessionScopeIt is used to access the value of any variable which is set in the Session scope
applicationScopeIt is used to access the value of any variable which is set in the Application scope
paramMap a request parameter name to a single value
paramValuesMap a request parameter name to corresponding array of string values.
headerMap containing header names and single string values.
headerValuesMap containing header names to corresponding array of string values.
cookieMap containing cookie names and single string values.
隐式对象 描述
pageContext 它代表PageContext对象。
pageScope 它用于访问在页面范围中设置的任何变量的值
requestScope 它用于访问在“请求”范围中设置的任何变量的值。
sessionScope 它用于访问在会话范围内设置的任何变量的值
应用范围 它用于访问在应用程序范围内设置的任何变量的值
参数 将请求参数名称映射到单个值
参数值 将请求参数名称映射到相应的字符串值数组。
标头 包含标题名称和单个字符串值的映射。
headerValues 将包含标题名称的映射映射到相应的字符串值数组。
曲奇饼 包含Cookie名称和单个字符串值的映射。

JSP EL的示例 (Example of JSP EL)

Let's take a simple example for understanding the JSP expression language,

让我们以一个简单的示例来了解JSP表达式语言,

index.jsp

index.jsp

<form method="POST" action="welcome.jsp">
    Name <input type="text" name="user" >
    <input type="submit" value="Submit">
</form>

welcome.jsp

welcome.jsp

<html>
    <head>
        <title>Welcome Page</title>
    </head>

  	<body>
        <h1>Welcome ${param.name}</h1>
  	</body>
</html>

EL中可用的算术运算 (Arithmetic Operations available in EL)

Following are the arithmetic operators avilable in EL:

以下是EL中适用的算术运算符:

Arithmetic OperationOperator
Addition+
Substraction-
Multiplication*
Division/ and div
Remainder% and mod
算术运算 操作员
加成 +
减法 -
乘法 *
/ and div
% and mod

EL中可用的逻辑运算符和关系运算符 (Logical and Relational Operators available in EL)

Following are the logical operator and comparators avilable in EL:

以下是适用于EL的逻辑运算符和比较器:

Logical and Relational OperatorOperator
Equals== and eq
Not equals!= and ne
Less Than < and lt
Greater Than > and gt
Greater Than or Equal >= and ge
Less Than or Equal <= and le
and && and and
or || and or
not ! and not
逻辑和关系运算符 操作员
等于 == and eq
不等于 != and ne
少于 < and lt
比...更棒 > and gt
大于或等于 >= and ge
小于或等于 <= and le
&& and and
要么 || and or
! and not

翻译自: https://www.studytonight.com/jsp/expression-language.php

jsp表达式语言

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值