EL's built-in objects

 EL built-in objects

In EL expressions, objects that can be used without creation are called EL hidden (implicit, built-in) objects. There are a total of 11 hidden objects in EL, and they are all similar to Map. 10 of them are Map and one is PageContext

parameter hidden object

    

l param: param is of type Map<String, String>! The param object can be used to get parameters, the same as the request.getParameter() method.

request.getParameter("username"); if then null then this result is null

And: param.username If it is empty then the return is an empty string ""


Single value accepts:

<form action="/jsp_demo/login.jsp" method="post">

	name:<input name="username">
	password:<input name="password" type="password">
	
	<input type="submit" value="提交">
	


</form>


<h1>${param.username }</h1>
<h1>${param.password }</h1>

Multiple values ​​are accepted:

<h1>${paramValues.favor[0] } , ${paramValues.favor[1] }</h1>

Get header information

<!-- Get header information-->
	
	<h1>${header.host }</h1>

cookie settings

<!-- cookie acquisition-->

	<!-- Set cookies first -->
	
	<%
		response.addCookie(new Cookie("personName","houzi"));
	%>
		
<!-- Get header information-->
	<h2>${cookie.personName.name } : ${cookie.personName.value }</h2>

pageScope gets the object in the domain

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   <!-- import package -->
   <%@ page import="cn.wgg.jsp.*" %>
<!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>

<%
	//create person object
	
	Person person = new Person();
	person.setAge(20);
	person.setName("houzi");
	person.setID(1);
	pageContext.setAttribute("person", person);
	
%>
<!-- pageScope takes value from field-->

<h2>${pageScope.person.name }</h2>
<h2>${pageScope.person.age }</h2>
<h2>${pageScope.person.ID }</h2>

<!-- Get header information-->
<!-- Get header information-->
</body>
</html>





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325931816&siteId=291194637