El Introduction
Expressive Language, JSP2.0 introduced, simplifies the reference to objects in JSP development.
Basic syntax
${-expression}
Common usage
According to its access to objects, can be broadly divided into three categories: access to data and its various expressions, access to the El's hidden objects and access to environmental information of the hidden objects.
(1) Accessing data and its various expressions
Access Data ${userinfo.id}//1. Access the id attribute of the userinfo: and [] to access the data, both of which are equivalent. ${userinfo[id]} ${userinfo.[ User-name]}//when a property name contains a special symbol, it can only be used [], not ${userinfo.user-name}${arrbook[0]}//2. (Suppose Arrbook an array object) access the first element in the Arrbook of the request range${goodslist[0]}//3. (Suppose Goodslist is a list object) accesses the first element of goodslist in the request scopearithmetic Operations ${5/2} or ${5 Div 2}//5 divided by 2 .${17%3} or%{17 mod 3}//17 to find the remainder 3${1+2}//Note + cannot implement concatenation of two strings, only arithmetic operations. empty ${empty user1}//user1==null or user1== "" will return true. Logical relational Operations ${10==10} or ${10 eq 10}//returns True${10!=10} or ${10 ne 10}//returns false${10<10} or ${10 lt 10}//returns false${10>=10} or ${10 ge 10}//returns True${true&&true} equivalent ${"true" && "true"}//the string is converted to Boolean for processing. ${!true} or ${nottrue} conditional Operation ${empty user1? "User1 is null or empty": user1}//determines whether the User1 is empty and then outputs the corresponding value.
(2) To access the hidden object of El
1. Get the page context object PageContext, you can access the JSP built-in objects and their property values and methods. (Request, response, out, session, application, etc.) Note: You cannot obtain a content variable saved to the request scope by PageContext object. ${pagecontext.response} //Gets response object ${pagecontext.response.contenttype} //Gets the content type of the returned response. ${pagecontext.session}/ /Get Session Object ${pagecontext.session.maxinactiveinterval} // Gets the value of the session's effective time 2. There are four hidden objects that access scope scopes: Pagescope, Requestscope, Sessionscope, applicationscope${pagescope.user.name} //Gets the Name property value of the user object within the page range ${requestscope.user1} //As previously set over <% Request.setattribute ("user1", "UUU");%>${ SESSIONSCOPE.USER2} //As previously set <% session.setattribute ("User2", "UUU");%> ${applicationscope.user3} // As previously set <% application.setattribute ("User3", "UUU"); %>
(3) Hidden objects that access environmental information
There are six: Param objects and Paramvalues objects, header and Headervalues objects, Iniparam objects, cookie objects
<% Cookie cookie = new Cookie ("User", "UUU"); Use the response object to set a request for a valid cookie object.
Response.addcookie (cookie); %>
${cookie.user.value} //Use El to get the value of the cookie object
El Expression Language Summary