*Expression Language 表达式语言,用于简化jsp页面中的Java语言
*主要功能:获取数据
*语法:{brands}意思是获取域中存储的key为brands的数据
*javaWeb中的四大域对象(el表达式会在这四个域中寻找,直到找到为止)
1.page:当前页面有效
2.request:当前的请求有效
3.session:当前的会话有效
4.application:当前应用有效

准备三个类
1.pojo包下的 实体类 brand
2.web包下的servlet类 servlet-el
3.webapp包下的jsp文件 el-demo
- package com.ithema.pojo;
- /*
- 在实体类中,基本数据类型,建议使用其对应的包装类
- */
- public class Brand {
-
- //id主键
- private Integer id;
- //品牌名称
- private String brandName;
- //企业名称
- private String companyName;
- //排序字段
- private Integer ordered;
- //描述信息
- private String description;
- //状态 0:禁用 1:启用
- private Integer status;
- public Brand(Integer id, String brandName, String companyName, Integer ordered, String description,
- Integer status) {
- super();
- this.id = id;
- this.brandName = brandName;
- this.companyName = companyName;
- this.ordered = ordered;
- this.description = description;
- this.status = status;
- }
- public Brand() {
- }
- @Override
- public String toString() {
- return "Brand [id=" + id + ", brandName=" + brandName + ", companyName=" + companyName + ", ordered=" + ordered
- + ", description=" + description + ", status=" + status + "]";
- }
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getBrandName() {
- return brandName;
- }
- public void setBrandName(String brandName) {
- this.brandName = brandName;
- }
- public String getCompanyName() {
- return companyName;
- }
- public void setCompanyName(String companyName) {
- this.companyName = companyName;
- }
- public Integer getOrdered() {
- return ordered;
- }
- public void setOrdered(Integer ordered) {
- this.ordered = ordered;
- }
- public String getDescription() {
- return description;
- }
- public void getDescription(String description) {
- this.description = description;
- }
- public Integer getStatus() {
- return status;
- }
- public void setStatus(Integer status) {
- this.status = status;
- }
- }
- package com.ithema.web;
-
- import com.ithema.pojo.Brand;
-
- import javax.servlet.*;
- import javax.servlet.http.*;
- import javax.servlet.annotation.*;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
-
- @WebServlet("/demo1")
- public class Servlet_el extends HttpServlet {
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- //1.准备数据 现在是list集合,以后是数据库
- List
brands= new ArrayList(); - brands.add(new Brand(1,"小米公司","小米科技有限公司",100,"为发烧而生",1));
-
- //2.储存带request域中进行转发
- request.setAttribute("brands",brands);
-
- //3.进行请求转发
- request.getRequestDispatcher("el-demo.jsp").forward(request,response);
-
- }
-
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- this.doGet(request, response);
- }
- }
- <%--
- Created by IntelliJ IDEA.
- User: HP
- Date: 2022/8/20
- Time: 15:07
- To change this template use File | Settings | File Templates.
- --%>
- <%@ page contentType="text/html;charset=UTF-8" language="java" %>
- <html>
- <head>
- <title>el表达式title>
- head>
- <body>
-
- ${brands}
-
- body>
- html>
