This is also a part of the JSP scope of knowledge, using El expression, can better use the various built-in objects and scopes in JSP, say a little gossip, immediately go out to practice, a little panic, it is possible to go out to work the common problem of students, continue to strive to put, the soldiers will block punches,
--wh
One, El expression
The EL expression can be used in the JSP, the El expression is a script enclosed in "${}" to make it easier to read the object, the El expression is written in the JSP's HTML code, but not in the "<%%>" caused by the JSP script, now to understand, How the EL expression replaces the JSP script or JSP behavior.
The EL expression has 11 built-in objects.
Pagescope, Requestscope, Sessionscope, Applicationscope,pagecontext, param, paramvalues, header, Headervalues, cookies, Initparam
Pagescope, Requestscope, Sessionscope, applicationscope represent four scope objects
PageContext represents a JSP built-in object PageContext, can get request and other JSP eight large built-in objects
param represents a request parameter ${param.username} equivalent Request.getparameter ("username");
Paramvalues represents a set of request parameters ${paramvalues.loves} equivalent Request.getparametervalues ("loves"); Submit Favorite this multi box
The header represents a request header ${header.referer} equivalent Request.getheader ("Referer");
Headervalues represents a set of request header ${header.cookie} equivalent Request.getheaders ("cookie"); Gets the contents of the request header parameter is a set of content, such as a cookie can be a number of cookies sent over
Cookie Access Cookie Object
Initpatam Web Project initialization parameters, Servletcontext.getinitparameter ("xxx");
There is also a special use to get object variables directly,
${user.username}
User is an instance object of user and is stored in the page scope, which means to look up the user object from page, request, session, application scope until it is found. The underlying use is Pagecontext.findattribute (); is the same effect.
Example Explanation:
Summarize:
El expression is relatively simple, it is used to reduce the JSP script, try not to embed Java code in HTML, it is very confusing, and the use of El Expression in HTML, it is better to get the various objects in the JSP, get the values in the four scopes,
If you want to get data from four scopes, you can use ${}, ${pagescope.xxx}
If you want to get request parameters, use param or paramvalues
If you want to get some information from the request header, get some objects to get the servlet, such as request, session, etc., you can use PageContext to get the request object, and then get the information you need, Or use header objects directly to get header information
If you want to get web initialization parameters, use the Initpatam
The operation of the El expression is not explained, very simple, basically can use all can use.
The main thing to remember is that there are 11 built-in objects in El, knowing that they know what information El can get.
Java Web (vi) EL expression