Use of Jsp built-in objects and EL expressions, and jsp built-in el expressions

Source: Internet
Author: User

Use of Jsp built-in objects and EL expressions, and jsp built-in el expressions

I. built-in JSP objects (9 built-in JSP objects)

 

Type of the JSP built-in object reference name

Request HttpServletRequest
Response HttpServletResponse
Session HttpSession (with a switch: the value of the session attribute of the page command)
Application ServletContext
Config ServletConfig
Page this (current Servlet object)
Exception java. lang. Throwable (the isErrorPage attribute of the page command is changed to true)
Out JspWriter
PageContext javax. servlet. jsp. PageContext is very important

 

 

The pageContext object has three major functions:

 

1. It is a domain object, indicating that the domain range is the current page.

At the same time, it can operate on three other domain objects (PageContext, ServletRequest, HttpSession, and ServletContext)

  

Set attributes:

Void setAttribute (String name, Object value)

Void removeAttribute (String name)

Object getAttribute (String name)

 

To operate on the other three domain objects, set the attributes:

Void setAttribute (String name, Object value, int scope)

Void removeAttribute (String name, int scope)

Object getAttribute (String name, int scope)

The int scope parameter is specified by the static variables provided by the PageContext class.

PageContext. PAGE_SCOPE: page range (the Map in PageContext itself, codenamed page)

PageContext. REQUEST_SCOPE: request range (the Map in ServletRequest, codenamed request)

PageContext. SESSION_SCOPE: Request range (the Map in HttpSession, codenamed session)

PageContext. APPLICATION_SCOPE: Request range (the Map in ServletContext, codenamed application)


Object findAttribute (String name): searches for objects with the specified name by page, request, session, and application.

The EL expression calls this method (very useful)

 

2. Obtain the other 8 implicit objects.

 

3. provides convenient methods for forwarding and inclusion

If you do not need a pageContext object:

RequestDispatcher rd = request. getRequestDispatcher ("/url ");

Rd. forward (request, response );

Use pageContext object:
PageContext. forward ("url ");

PageContext. include ("url ");

 

 

Four domain objects (data transfer between two resources)

Type of the name range name of the implicit object in JSP

PageContext page javax. servlet. jsp. PageContext
Request javax. servlet. ServletRequest
Session javax. servlet. http. HttpSession
Application javax. servlet. ServletContext (if used, it must be processed synchronously)

 

Ii. EL expression

 

It is only an expression in JSP, not a development language.

Basic Syntax: $ {EL expression}


1. Get Data

An EL expression can only obtain data in four fields.

If the object obtained by the EL expression is null, the page does not display data. Therefore, there will never be a null pointer exception in the EL expression.

 

"." OPERATOR:

$ {P. name}: Call the getName method of the object named p in the field. The vertex operator is used to obtain the attribute value.

"[]" OPERATOR:

([] Can do what the. operator can do. [] What can be done. Not always can be done)

For example, $ {p. name }=== {p ['name'] }== {p ["name"]}

Excellent.


2. mathematical logic operations:

Empty OPERATOR: if the object to be determined is null or a null String, true is returned.

For a set, true is returned even if the set object is not null and has no elements.

The EL expression does not support string join operations.

 

3. EL built-in objects (11 EL built-in objects)

 

Get the built-in JSP objects (11 EL built-in objects): difficult. Do not mix them with the built-in JSP objects and range names.

Among the 11 large EL implicit objects, one of them represents the external objects, and the other is the Map structure.

EL implicit Object Name Java type Remarks

 

PageContext javax. servlet. jsp. PageContext is identical to the built-in objects in JSP.


The rest are Map sets.

Pagination java. util. Map represents the Map of the PageContext page range domain.

RequestScope java. util. Map represents the Map in the scope field of the ServletRequest request

SessionScope java. util. Map represents the Map in the range field of the HttpSession.

ApplicationScope java. util. Map represents the Map of the application scope domain of ServletContext.


Param java. util. Map represents the request parameters. Key: the name of the request parameter. Value: the value of the request parameter. It is a string.

ParamValues java. util. Map represents the request parameters. Key: the name of the request parameter. Value: the value of the request parameter. It is a string array.


Header java. util. Map represents the request message header. Key: header name. Value: the header value. It is a string.

HeaderValues java. util. Map represents the request message header. Key: header name. Value: the header value, which is a string array.

Cookie java. util. Map indicates the Cookie Map submitted by the client. Key: cookie name. Value: cookie object itself

InitParam java. util. Map represents the global initialization parameter (context-param in web. xml). key: parameter name. Value: Parameter value

 

Blog blog: A small basket that is not flushed

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.