EL
1 What is EL
Expression Language (EL), which JSP setters can use to access application data, EL can easily write JSP pages that do not contain scripts or Java code.
2 Syntax
a, ${expression} The type of the result is forced to String
If an EL expression is used in an attribute of a custom tag, the expression will be evaluated and the resulting string will be forced to the desired type of the attribute
<my:tag somAttribute="${expression}"/>
b, [] and . operators
If there is a property in the result object of an EL expression, it can be used to access it.
${object["propertyName"]}
${object.propertyName}
c, implicit object of EL
EL provides its own set of implicit objects that can help you access various objects.
1、pageContext
2、initParam
Used to get the value of a context parameter; for example, to get the password of the context parameter, you need to use
${initParam.password}
3、param
Used to get a request parameter. This object represents a Map containing all request parameters.
To get userName ${param.userName}
4、paramValues
Multiple values for a request parameter can be obtained. This object represents a Map containing all request parameter names as keys. The value of each key is an array of strings,
which contains all the values for the specified parameter name. If the parameter has only one value, an array with only one element is also returned.
${paramValues.selectOption[i]}
5、header
Represents a Map containing all request headers. To get a header value, you need to use that header as a key.
${header["accept-language"]}
6、headerValues
Represents a Map containing all request headers and keyed by the header name, the returned Map returns an array of strings.
${header["accept-language"][0]}
7、cookie
A map representing all cookies in the current HttpServletRequest
8、applicationScope、sessionScope、requestScope、pageScope
Get the value of an application-scoped variable. ${applicationScope.myVar.value}
3. Summary
EL can help you write shorter and more efficient JSP pages, as well as help you write scriptless pages.
1 What is EL
Expression Language (EL), which JSP setters can use to access application data, EL can easily write JSP pages that do not contain scripts or Java code.
2 Syntax
a, ${expression} The type of the result is forced to String
If an EL expression is used in an attribute of a custom tag, the expression will be evaluated and the resulting string will be forced to the desired type of the attribute
<my:tag somAttribute="${expression}"/>
b, [] and . operators
If there is a property in the result object of an EL expression, it can be used to access it.
${object["propertyName"]}
${object.propertyName}
c, implicit object of EL
EL provides its own set of implicit objects that can help you access various objects.
1、pageContext
2、initParam
Used to get the value of a context parameter; for example, to get the password of the context parameter, you need to use
${initParam.password}
3、param
Used to get a request parameter. This object represents a Map containing all request parameters.
To get userName ${param.userName}
4、paramValues
Multiple values for a request parameter can be obtained. This object represents a Map containing all request parameter names as keys. The value of each key is an array of strings,
which contains all the values for the specified parameter name. If the parameter has only one value, an array with only one element is also returned.
${paramValues.selectOption[i]}
5、header
Represents a Map containing all request headers. To get a header value, you need to use that header as a key.
${header["accept-language"]}
6、headerValues
Represents a Map containing all request headers and keyed by the header name, the returned Map returns an array of strings.
${header["accept-language"][0]}
7、cookie
A map representing all cookies in the current HttpServletRequest
8、applicationScope、sessionScope、requestScope、pageScope
Get the value of an application-scoped variable. ${applicationScope.myVar.value}
3. Summary
EL can help you write shorter and more efficient JSP pages, as well as help you write scriptless pages.