2016.5.10 (write Java Script-free JSP page)

Source: Internet
Author: User
Tags arithmetic operators logical operators map class tld

JSP expression Language El

Display results in JSP pages Jsp:usebean and jsp:getproperty two elements lengthy and clumsy
Jsp:getproperty only supports access to simple bean properties

Using the JSP EL

The property attribute of the <jsp:getProperty> can only access the bean's properties, not the nested properties
Using the JSP EL (expression language Language)

<%@ page contenttype= "text/html; charset=gb2312 "%>
<body>
My dog's name is: ${person.dog.name}
</body>


El Expressions and JSP script expressions
${person.name}

Comparison with JSP script expressions
The outdoor temperature is <%= temp%> degree.
If El is used, it is: Outdoor temperature is ${temp} degrees.
The L expression begins with "${", Ends with "}", and the JSP script expression begins with "<%" and ends with "%>".
An El expression cannot define a variable in a script. The goal is to remove Java code from the JSP page


Using an implicit variable in an EL expression

Category implicit variable name description
JSP PageContext an implicit object used to access the JSP
Scope Pagescope the Map class associated with the name and value of the page scope property
Requestscope the Map class associated with the name and value of the request scope property
Sessionscope the Map class associated with the name and value of the session scope property
Applicationscope the Map class associated with the name and value of the application scope property
Request parameter param the map class containing the request parameter string
Paramvalues Map class containing an array of request parameter strings (string[])
The request header header contains the Map class for the request header string
Headervalues Map class containing an array of request header strings (string[])
Cookie cookie the Map class that stores the cookie that is included in the request by name


El operator
The EL operator can be divided into four classes
Properties and Collections
Access operator
Arithmetic operators
Relational operators
logical operators

To access the properties and collection of the EL Operator:
A.B: Returns the value of property B of a.
A[B]: Returns the key of a or the value of index B.


El function

Provides complete logical separation of business logic and performance for JSPs
Steps for using the EL function
Method Class (. java): Contains Java methods that need to be used in the JSP;
Tag library description file (*.TLD): Maps Each Java method to an XML function name;
Deployment description file (Web. xml): Map TLD to tag library URI
JSP page (*.jsp): Invokes a method using the tag library URI and function name.


The main purpose of SP El is to simplify the development of JSP
The EL expression is always enclosed in curly braces and preceded by a dollar symbol prefix
An implicit variable is available in El
The EL function provides a complete separation of business logic and presentation logic for JSPs
The JSTL1.1 specification defines five standard tag libraries, namely core tag libraries, XML tag libraries, SQL tag libraries, internationalized tag libraries, function tag libraries
JSTL core tags include generic tags <c:catch> and <c:out>, variable support tags <c:set> and <c:remove>,
Process Control Tags <c:if>, <c:choose>, <c:forEach> and <c:forTokens>, URL processing tags <c:url>, <c:import > and <c:redirect>

2016.5.10 (write Java Script-free JSP page)

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.