标签:[] height 全局参数 rar tty script 表达 short scope
<% List<User> users = (List<User>) request.getSession().getAttribute("users"); out.write(users.get(0).getUsername()); %>
${users[0].name}
package com.domain; import java.io.Serializable; /** * 2017/11/6 * 说明: */ public class Student implements Serializable { private String name; private int age; private String gender; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } }
<%@ page import="com.domain.Student" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>EL表达式</title> </head> <body> <% Student student = new Student(); student.setName("刘谦"); student.setAge(29); student.setGender("男"); pageContext.setAttribute("student",student); %> ${student} <%-- ${student} 相等于 Student student = (Student)pageContext.findAttribute("student"); out.write(student) --%> </body> </html>
<%@ page import="com.domain.Student" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>EL表达式</title> </head> <body> <% Student student = new Student(); student.setName("刘谦"); student.setAge(29); student.setGender("男"); pageContext.setAttribute("student",student); %> ${student.name} <%-- ${student} 相等于 Student student = (Student)pageContext.findAttribute("student"); out.write(student.getName()) --%> </body> </html>
package com.domain; /** * 2017/11/6 * 说明: */ public class Address { private String province; private String city; public String getProvince() { return province; } public void setProvince(String province) { this.province = province; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } }
package com.domain; import java.io.Serializable; /** * 2017/11/6 * 说明: */ public class Student implements Serializable { private String name; private int age; private String gender; private Address address = new Address(); public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } }
<%@ page import="com.domain.Student" %> <%@ page import="com.domain.Address" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>EL表达式</title> </head> <body> <% Address address = new Address(); address.setProvince("江苏省"); address.setCity("泰州市"); Student student = new Student(); student.setName("刘谦"); student.setAge(29); student.setGender("男"); student.setAddress(address); pageContext.setAttribute("student",student); %> ${student.address.province} </body> </html>
<%@ page import="com.domain.Student" %> <%@ page import="com.domain.Address" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>EL表达式</title> </head> <body> <% String[] strs = {"aa","bb"}; pageContext.setAttribute("strs",strs); %> ${strs[0]} </body> </html>
<%@ page import="com.domain.Student" %> <%@ page import="com.domain.Address" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.Map" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>EL表达式</title> </head> <body> <% Map<String,String> map = new HashMap<>(); map.put("aa","bb"); map.put("cc","dd"); pageContext.setAttribute("map",map); %> ${map.aa} </body> </html>
<%@ page import="com.domain.Student" %> <%@ page import="com.domain.Address" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.List" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>EL表达式</title> </head> <body> <% List<String> list = new ArrayList<>(); list.add("aa"); list.add("bb"); pageContext.setAttribute("list",list); %> ${list[0]} </body> </html>
<%@ page import="com.domain.Student" %> <%@ page import="com.domain.Address" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.List" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>EL表达式</title> </head> <body> <% List<String> list = new ArrayList<>(); pageContext.setAttribute("s",""); pageContext.setAttribute("s1",null); pageContext.setAttribute("s2",list); %> ${empty s1}<%--true--%> ${empty s1}<%--true--%> ${empty s2}<%--true--%> </body> </html>
<%@ page import="com.domain.Student" %> <%@ page import="com.domain.Address" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.List" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>EL表达式</title> </head> <body> <% pageContext.setAttribute("gender","男"); %> <input type="radio" name="gender" value="男" ${gender == "男"?"checked=‘true‘":""}>男<br/> <input type="radio" name="gender" value="女" ${gender == "女"?"checked=‘true‘":""}>女<br/> </body> </html>
EL隐式对象的名称 | 表示的类型 | JSP的隐式对象 | 备注 |
pageContext | javax.servlet.jsp.PageContext | pageContext | 一样 |
pageScope | java.utl.Map | 没有 | 页面域范围的数据 |
sessionScope | java.utl.Map | 没有 | reqeust域范围的数据 |
requestScope | java.utl.Map | 没有 | session域范围的数据 |
aplicattionScope | java.utl.Map | 没有 | application域范围的数据 |
header | java.utl.Map | 没有 | key:请求消息头 value:消息头对应的值 |
headerValues | java.utl.Map | 没有 | key:请求消息头 value:消息头对应的值数组 |
param | java.utl.Map | 没有 | key:请求参数名,value:请求参数值 |
paramValues | java.utl.Map | 没有 | key:请求参数名,value:请求参数值数组 |
cookie | java.utl.Map | 没有 | key:Cookie对象的name ,value是Cookie对象本身 |
initParam | java.utl.Map | 没有 | key:全局参数的name,value是全局参数的值 |
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>EL表达式</title> </head> <body> <% pageContext.setAttribute("p","p"); request.setAttribute("p","rp"); session.setAttribute("p","sp"); application.setAttribute("p","ap"); %> ${p} <%=pageContext.findAttribute("p")%> <br/> ${pageScope.p} <%=pageContext.getAttribute("p")%> <br/> ${requestScope.p} <%=request.getAttribute("p")%> <br/> ${sessionScope.p} <%=session.getAttribute("p")%> <br/> ${applicationScope.p} <%=application.getAttribute("p")%> <br/> </body> </html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>EL表达式</title> </head> <body> ${header["Accept-Encoding"]}<br/> <%=request.getHeader("Accept-Encoding")%> </body> </html>
package com; /** * 2017/11/6 * 说明: */ public class ELFunction { public static String toUpperCase(String str) { return str.toUpperCase(); }}
<?xml version="1.0" encoding="UTF-8"?> <taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1"> <tlib-version>1.0</tlib-version> <short-name>elfunction</short-name> <uri>http://www.xuweiwei.com/jsp/functions</uri> <function> <name>toUpperCase</name> <function-class>com.ELFunction</function-class> <function-signature>java.lang.String toUpperCase(java.lang.String)</function-signature> </function> </taglib>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="elfunction" uri="http://www.xuweiwei.com/jsp/functions" %> <html> <head> <title>EL表达式</title> </head> <body> <% pageContext.setAttribute("s","abcde"); %> ${elfunction:toUpperCase(s)} </body> </html>
标签:[] height 全局参数 rar tty script 表达 short scope
原文地址:http://www.cnblogs.com/xuweiweiwoaini/p/7792413.html