Java Web (VI) el expression

This is also the knowledge within the scope of JSP. Using El expressions can make better use of various built-in objects and scopes in JSP, gossip, and go out for internship soon. It's a little panic. Maybe this is a common problem of students who are going out to work soon. Continue to work hard to block the soldiers from the water and the earth,

                            --WZY

1、 El expression

El expression can be used in JSP. El expression is a script enclosed by "${}" to read objects more conveniently. El expression is written in JSP HTML code, not in JSP script caused by "<%% >". Now let's learn how El expression replaces JSP script or JSP behavior.

El expressions have 11 built-in objects.

       pageScope、requestScope、sessionScope、applicationScope、pageContext、param、paramValues、header、headerValues、cookie、initParam

Pagescope, requestscope, sessionscope and applicationscope represent four scope objects

Pagecontext represents the built-in object pagecontext in JSP, which can obtain eight other built-in objects in JSP such as request

Param represents a request parameter ${param. Username} equivalent to request getParameter("username");

Paramvalues represents a set of request parameters ${paramvalues. Loves} equivalent to request getParameterValues("loves"); Submit like this multi box

Header represents a request header ${header. Referer} equivalent to request getHeader("referer");

Headervalues represents a set of request headers ${header. Cookie} equivalent requests getHeaders("cookie"); The contents in the obtained request header parameters are a group of contents. For example, cookies can be transmitted together by multiple cookies

Cookie get cookie object

Initpatam web project initialization parameter, ServletContext getInitParameter("xxx");

There is also a special usage, which directly obtains object variables,

      ${user.username}

User is an instance object of user and stored in the page scope. The above code means to find the user object from the page, request, session and application scope until it is found. The bottom layer uses pagecontext findAttribute(); Is the same effect.

Example explanation:

Summary:

El expression is relatively simple. The purpose of using it is to reduce JSP scripts. Try not to embed java code in HTML, which is very chaotic. Using El expression in html is better to obtain various objects in JSP and values in the four scopes,

If you want to get data from the four scopes, ${}, ${pagescope. XXX}

If you want to get the request parameters, use param or paramvalues

If you want to obtain some information in the request header and some objects of the servlet, such as request and session, you can use pagecontext to obtain the request object, and then obtain the required information, or directly use the header object to obtain the header information

If you want to get the web initialization parameters, use initpatam

The operation of El expression is not explained. It is very simple. Basically, everything that can be used can be used.

The most important thing is to remember which 11 built-in objects are in El, and they will know what information El can obtain.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>