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");
相关推荐
wrx繁星点点7 分钟前
事务的四大特性(ACID)
java·开发语言·数据库
IT学长编程14 分钟前
计算机毕业设计 Java酷听音乐系统的设计与实现 Java实战项目 附源码+文档+视频讲解
java·spring boot·毕业设计·课程设计·毕业论文·音乐系统·计算机毕业设计选题
IT学长编程31 分钟前
计算机毕业设计 基于协同过滤算法的个性化音乐推荐系统的设计与实现 Java实战项目 附源码+文档+视频讲解
java·spring boot·毕业设计·毕业论文·协同过滤算法·计算机毕业设计选题·个性化音乐推荐系统
小小娥子36 分钟前
Redis的基础认识与在ubuntu上的安装教程
java·数据库·redis·缓存
几何心凉43 分钟前
已解决:org.springframework.web.HttpMediaTypeNotAcceptableException
java
华农第一蒟蒻1 小时前
Java中JWT(JSON Web Token)的运用
java·前端·spring boot·json·token
两点王爷1 小时前
使用WebClient 快速发起请求(不使用WebClientUtils工具类)
java·网络
计算机学姐1 小时前
基于SpringBoot+Vue的高校运动会管理系统
java·vue.js·spring boot·后端·mysql·intellij-idea·mybatis
平凡的小码农1 小时前
JAVA实现大写金额转小写金额
java·开发语言
一直在进步的派大星1 小时前
Docker 从安装到实战
java·运维·docker·微服务·容器