javaee el表达式

java 复制代码
package com.test.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.test.pojo.Student;

/**
 * Servlet implementation class TestElServlet
 */
@WebServlet("/TestElServlet")
public class TestElServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TestElServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	
		request.setAttribute("uname", "daimenglaoshi");
		
		HttpSession session=request.getSession();
		
		session.setAttribute("uname", "daimenglaoshi2");
		
		Student student=new Student();
		student.setSid(1);
		student.setSname("aa");
		student.setMajor("english");
		student.setStu_class("0101");
		
		request.setAttribute("mystudent", student);
		
		List<Student> list=new ArrayList<Student>();
		
		list.add(student);
		
		Student student2=new Student();
		student2.setSid(2);
		student2.setSname("bb");
		student2.setMajor("english");
		student2.setStu_class("0101");
		list.add(student2);
		
		request.setAttribute("mylist", list);
		
		
		request.getRequestDispatcher("index.jsp").forward(request, response);
		
		
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
html 复制代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

${uname}<br/>
${sessionScope.uname}<br/>
${mystudent.sid}<br/>
${mystudent.sname}<br/>
${mylist[1].sid}<br/>

${param.id}
</body>
</html>
html 复制代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="index.jsp?id=1">传参</a>
</body>
</html>

EL一共11个内置对象,无需创建即可以使用。这11个内置对象中有10个是Map类型的,最后一个是pageContext对象。

pageScope

requestScope

sessionScope

applicationScope

param;

paramValues;

header;

headerValues;

initParam;

cookie;

pageContext;

域内置对象一共有四个:

bash 复制代码
pageScope:${pageScope.name}等同与pageContext.getAttribute("name");
requestScope:${requestScope.name}等同与request.getAttribute("name");
sessionScoep: ${sessionScope.name}等同与session.getAttribute("name");
applicationScope:${applicationScope.name}等同与application.getAttribute("name");
相关推荐
nbsaas-boot7 分钟前
SaaS 租户上下文传播架构
java·架构·saas
西岭千秋雪_31 分钟前
Zookeeper监听机制
java·linux·服务器·spring·zookeeper
毕设源码-林学长35 分钟前
计算机毕业设计java和Vue的安全教育科普平台设计与实现 安全知识普及与教育平台 安全教育信息化管理平台
java·开发语言·课程设计
ruleslol39 分钟前
java-接口适配器模式 & jsk8 接口默认实现
java·适配器模式
鬼火儿1 小时前
网卡驱动架构以及源码分析
java·后端
老华带你飞1 小时前
房屋租赁|房屋出租|房屋租赁系统|基于Springboot的房屋租赁系统设计与实现(源码+数据库+文档)
java·数据库·spring boot·vue·论文·毕设·房屋租赁系统
TDengine (老段)1 小时前
TDengine 数学函数 ASCII 用户手册
java·大数据·数据库·物联网·时序数据库·tdengine·涛思数据
123461611 小时前
互联网大厂Java面试:从Spring Boot到微服务的探索
java·数据库·spring boot·微服务·面试·mybatis·orm
光仔December1 小时前
【Elasticsearch入门到落地】18、Elasticsearch实战:Java API详解高亮、排序与分页
java·elasticsearch·es排序·es分页·es高亮
码上零乱1 小时前
跟着小码学算法Day19:路径总和
java·数据结构·算法