"JSP" El expression language

Source: Internet
Author: User
Tags session id


El introduction El language was originally JSTL1.0 technology (so El and Jstl together so close and tacit understanding is natural), but from the beginning of the JSP2.0 (JSTL1.1) separated out into the JSP standard. So El does not need any jar packages, he is integrated into the JSP technology itself. Since El Positioning is Expression Language, so El can only be used to do simple operations and values, it is a JSP without scripting a tool, very easy to learn. characteristics of El 1, the format of all El expressions ${  expression  }, such as fetching an object user's Age property ${User.Name} 2, can be used on any custom label (including Jstl, JSP Acti On,el function), or as the response text data of a JSP.  3, as the response text data of the JSP,   if the value of the EL expression is null, he will not display anything.   Basic types because El is an expression language, you have no chance to define variables, i.e. no type keywords such as int or char. You can only use literal or object property quantities.  bool Boolean:    true    false integer type  :   such as, -1, 0 ...  float type float: &nb SP; such as 0.12,  90.123  , -190.123,1.0e2 ...  String type string: such as   ' Hello '  ,   "Hello"   ... &nbs P (You can use single quotes, or double quotes)   reference types:    null and non-null (mainly JavaBean objects, Java.util.Map  , java.util.List, Java numbers, Java strings and El Implicit objects)   reserved words and      or       notdiv       MODIF   &N Bsp      emptyge        ne      EQ     GT     LT  t Rue      falsenull       instanceof   operator El Built-in operator if it doesn't meet your needs., you can also use Jstl,jstl, and you can also use custom tags and custom el functions.  
Type Operator Note
Arithmetic operations +      -      *        /      % Note that division is a floating-point division, 7/5=1.2
Logical operations && | | !
Relational operations > >= < <= = = =! Can be used for strings, sorted in dictionary order
Ternary operations ${condition? EXPA:EXPB} Like ${sessionscope.user==null? "You are not logged in": "You have logged in"}
Null judgment Empty Object If object is null, it returns true directly. Otherwise, the object is map, List, lease, string if it is empty (size=0), then return True. He is a prefix operator.
Delimiter ( ) Control operator Precedence
Property Get operator [] or.

The property used to get the object. Obj.pro equivalent to obj["Pro"]. Returns null if one of the obj and Pro is null.

The latter point operators are more common, but if property Pro is not a valid Java identifier, you must use [] to take the property.

The objects in El and their properties


There are 2 operators in Le that are used to take object properties: [] and.



In general, the latter is used more often. However, if the property contains non-Java identifiers, such as "-", you must use [] to take the property.
El's main objects are: JavaBean objects, Java.util.Map, java.util.List, Java numbers, Java strings, and El Implicit objects. Property operators are used to take their properties.



Attribute operators can be used with: such as User.address.postCode, pagecontext.request["method"]






JavaBean



To use the JavaBean property of El, first this attribute must satisfy the specification of JavaBean. We can store a JavaBean object in Pagescope,requestscope,sessionscope or Applicationscope, and when using El to extract the properties of the JavaBean object, Instead of specifying what scope the JavaBean is stored in, he will automatically find it from Pagescope,requestscope,sessionscope, Applicationscope, Returns the value for the first time (because the Findattribute method for the PageContext object is used internally). But in order to make the code clearer, specifying scope explicitly is also a no-no.


 Package
package model;

public class User
{
       private String name;
       private int age;
       public String getName () {
             return name;
       }
       public void setName (String name) {
             this .name = name;
       }
       public int getAge () {
             return age;
       }
       public void setAge (int age) {
             this .age = age;
       }
}
<% @ page contentType = "text / html; charset = UTF-8" pageEncoding = "UTF-8" trimDirectiveWhitespaces = "true"
          session = "true"%>

<% @ page import = "model. *"%>

<%-Store a user in pageScope and initialize the age attribute to 21-%>

<jsp: useBean id = "user" class = "model.User" scope = "page">
       <jsp: setProperty name = "user" property = "age" value = "$ {param.age}" />
</ jsp: useBean>

user's age attribute value: $ (user.age) <br />
user's age attribute value: $ (pageScope.user.age) <br />







Java.util.MapMapobj [key] If one of the map or key is NULL, it returns NULL if the map does not contain key, return null otherwise return the value corresponding to the map key




Java.util.List and Java arraysArrobj[index] If one of the arrobj and index is NULL, it returns NULL if index cannot be converted to int, an exception is thrown. Index out of bounds returns null otherwise returns an implicit object in the element value El in the list or at the corresponding index of the array
Pagescope Page range, which is a map container that stores the K-v property.
Requestscope Request scope, which is a map container that stores k-v properties
Sessionscope Session range, which is a map container that stores k-v properties
Applicationscope Application range, is a map container that stores k-v properties
Param

Stores the map container for parameter paramter. Equivalent to Request.getparameter ().

Used to take single-valued request parameters. If used to get a multivalued parameter, such as the value of a checkbox, only the first value is returned.

Paramvalues Used to get multi-valued request parameters. A string array that returns all values (for example, a checkbox). If this parameter has only one value, it returns an array of only 1 elements. Equivalent to Request,.getparametervalues ()
PageContext This is the implicit object PageContext in the JSP. PageContext the context object of the JSP page. You can get the other 8 large objects. ${pagecontext.request.method} Gets the current request method. ${pagecontext.session.id} is equivalent to Session.getid () ${pagecontext.request.querystring} to obtain the requested query string ${ PageContext.request.requestURL} Gets the name of the Web application of the requested URL ${pagecontext.request.contextpath} service ${ PageContext.request.method} Get HTTP method (GET, POST) ${pagecontext.request.protocol} Get used Protocol (http/1.1, http/1.0) ${ PageContext.request.remoteUser} Get the user name ${pagecontext.request.remoteaddr} Get the user's IP address ${pagecontext.session.new} Determine if the session is a new ${pagecontext.session.id} get session Id${pagecontext.servletcontext.serverinfo} Get the service information of the host side
Initparam The getinitparameter of the ServletContext object. A map container for the global initial parameters configured in Web. xml
Cookies Represents a map in all cookie objects that hold the current request, and the name of each cookie is key.
Header A map that contains all the request headers. Used to access a single-valued request header. If used to access a multi-valued request header, the value returns the first value. ${header["Accept-language"]}${header.connection}
Headervalues Used to get a multi-valued request header. A string array that returns the value of the multi-value header. If the header field has only one value, it returns an array of only 1 elements.
The El function and the custom El function are described in another article: http://www.cnblogs.com/lulipro/p/7230598.html


"JSP" El expression language


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.