Dynamic page technology EL, dynamic page el

Source: Internet
Author: User

Dynamic page technology EL, dynamic page el

1. EL Overview:

EL expressions can be embedded inside JSP pages to reduce the compilation of JSP scripts.

EL appears to replace the compiling of scripts on JSP pages.

 

EL's most important role is to retrieve data from the domain:

Introduction:

<% = Request. getAttribute (name); %>

EL only needs to write like this: $ {requestScope. name}

 

Details:

Create a User class:

package domain;public class User {    private int id;    private String name;    private String password;    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public String getPassword() {        return password;    }    public void setPassword(String password) {        this.password = password;    }    }
View Code

 

Create a JSP file as an example:

Prepare some data:

<! -- Simulate data in the Domain --> <% pageContext. setAttribute ("company", "Microsoft"); // stores the string request. setAttribute ("company", "Microsoft"); // stores an Object User user = new User (); user. setId (1); user. setName ("zhangsan"); user. setPassword ("123"); session. setAttribute ("user", user); // store a collection List <User> list = new ArrayList <User> (); User user1 = new User (); user1.setId (2); user1.setName ("lisi"); user1.setPassword ("123"); list. add (user1); User user2 = new User (); user2.setId (3); user2.setName ("wangwu"); user2.setPassword ("123"); list. add (user2); application. setAttribute ("list", list); %>
View Code

JSP retrieves the value in the field:

<! -- JSP retrieves the value in the field --> <% = request. getAttribute ("company") %> <% User sessionUser = (User) session. getAttribute ("user"); out. write (sessionUser. getName (); %>

EL mode:

<! -- Use the EL expression to obtain the value in the field -- >$ {requestScope. company }$ {sessionScope. user. name }$ {applicationScope. list [1]. name}

Global Search (commonly used ):

<! -- Use the el expression for global search -- >$ {company }$ {user. name }$ {list [1]. name}

The global search sequence is the same as that of findattricontext: pageContext-> request-> session-> application

 

EL built-in object:

 

These are outdated and are not used in actual development.

Pay attention to the last one: other objects such as request and response can be obtained.

Example: $ {pageContext. request. contextPath}

 

EL execution expression:

<! -- El can execute expression operations -- >$ {1 + 1 }$ {1 = 1? True: false} <! -- Empty: determines whether an object is null. If it is null, true is returned. -- >$ {empty list}

 

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.