Detailed instructions on the use of EL Expression Language and jstl tag library in JSP pages, eljstl

Source: Internet
Author: User

Detailed instructions on the use of EL Expression Language and jstl tag library in JSP pages, eljstl
Limitations of JavaBean in JSP
To obtain the JavaBean attribute, you must instantiate it.
Forced type conversion

<%    Employee employee = (Employee)request.getAttribute("employee");    Computer comp = employee.getComputer();    String manufacturer = comp.getManufacturer();%>

If a logic error occurs in page compilation, code execution errors may occur and errors may occur during page compilation on the JSP page.


Solution
Simplified using EL expressions

What is EL?
EL is Expression Language)
EL features
Replaces the complex code in the JSP page
EL syntax
$ {EL exprission}
$ {Bean. name} or $ {bean ['name']}

$ {Bean. name} is actually calling the getName () method of bean.

Note: 1 el accesses data through. And. For example, $ {applicationScope. user. userName} or $ {applicationScope. user ["userName"]}

2. If the accessed property name contains some special characters, such as "." or "-" and other non-letter or digit symbols, you must use []

3 applicationScope. user ["user-Name"]

4. If variables are used for input, you can only use []. For example:

<% String data = "username"; %>

$ {ApplicationScope. user [data]}

5 of course, there are four implicit objects: applicationScope, sessionScope, requestScope, pagscope. correspond to application, session, request, and pageContext. For example, applicationScope is used to obtain the attribute values in the application range.

Automatic Conversion Type
The data type can be automatically converted when EL obtains data.
More relaxed restrictions on Types
Easy to use
Compared with embedding Java code in JSP, EL application is simpler



EL syntax



Start with "$ {" and end "}"
Get the value directly using the variable name $
$ {Username}



Variable attribute range name

Name in attribute range EL
Page pagination, for example, $ {pagination. username}, indicates to search for the username variable in the page range. If no value is found, Null is returned.
Request requstScope
Session sessionScope
Application applicationScope


EL Operator
Operator "[]"
Operator "."
Function
Get Object Attributes




Obtain data in an object set
Saves a list set of users in the Session.



Simple Application: Output name display

<%
Map names = new HashMap ();
Names. put ("one", "LiYang ");
Names. put ("two", "WangHua ");
Request. setAttribute ("names", names );
%>
Name: $ {names. one} <br/>
Name: $ {names ["two"]} <br/>



Introduction to EL implicit objects


Object Name Description
Pagination returns the variable names in the page range, which have been mapped to the corresponding values.
RequestScope returns the variable names in the request range. These names have been mapped to the corresponding values.
SessionScope returns the variable names in the session range. These names have been mapped to the corresponding values.
ApplicationScope returns the variables within the application range and maps the variable names to the corresponding values.
Param returns the string value of the client's request parameter
ParamValues returns a set of values mapped to the client's request parameters.
PageContext provides access to user requests and page information


The EL expression can simplify JSP page code, but what if logical judgment is required?

Click to view JSTL label library Introduction

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.