标签:str esc port object get ons content objects 页面
<%@ page import="java.util.ArrayList" %> <%@ page import="java.util.List" %><%-- User: 丁帅帅 Date: 21/05/30 Time: 10:00 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> ${3>4} \${3>4} <hr> <h3>算术运算符</h3> ${3+4}<br> ${3/4}<br> ${1 div 4}<br> ${3 % 4}<br> ${3 mod 4}<br> <h3>比较运算符</h3> ${3 == 4}<br> <h3>逻辑运算符</h3> ${3 > 4 && 3 < 4}<br> ${3 > 4 and 3 < 4}<br> <h4>empty运算符</h4> <% String str=""; request.setAttribute("str",str); List<Object> objects = new ArrayList<>(); request.setAttribute("list",objects); %> ${empty str} <br> ${not empty list} </body> </html>
<%-- User: 丁帅帅 Date: 21/05/30 Time: 10:23 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> <% request.setAttribute("name","李四"); session.setAttribute("age",23); %> <h3>el获取值</h3> ${requestScope.name} <br> ${sessionScope.age} <br> ${name} </body> </html>
package com.ding.domain; import java.text.SimpleDateFormat; import java.util.Date; import java.util.logging.SimpleFormatter; /** * @Description TODO * @Author 丁帅帅 * @Date 21/05/30 10:28 * @Version 1.0 */ public class User { private String name; private int age; private Date birthday; public User() { } public User(String name, int age, Date birthday) { this.name = name; this.age = age; this.birthday = birthday; } 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 Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getBirStr(){ if(birthday!=null){ //1.格式化日期对象 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd-HH:mm::ss"); //2.返回字符串 return sdf.format(birthday); } return ""; } } <%@ page import="com.ding.domain.User" %> <%@ page import="java.util.*" %><%-- User: 丁帅帅 Date: 21/05/30 Time: 10:39 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> <% User user=new User(); user.setName("张三"); user.setAge(23); user.setBirthday(new Date()); request.setAttribute("u",user); List list=new ArrayList<>(); list.add("aaa"); list.add("bbb"); list.add(user); request.setAttribute("list",list); Map map=new HashMap(); map.put("sname","李四"); map.put("gender","男"); map.put("user",user); request.setAttribute("map",map); %> <%-- * 通过的是对象的属性来获取 * setter或getter方法,去掉set或get,在将剩余部分,首字母变为小写。 * setName --> Name --> name --%> <h3>el获取对象中的值</h3> ${requestScope.u}<br> ${requestScope.u.name}<br> ${u.age}<br> ${u.birthday}<br> ${u.birthday.month}<br> ${u.birStr}<br> <h3>el获取List值</h3> ${list}<br> ${list[0]}<br> ${list[1]}<br> ${list[10]}<br> ${list[2].name} <h3>el获取Map值</h3> ${map.gender}<br> ${map["gender"]}<br> ${map.user.name} </body> </html>
<%-- User: 丁帅帅 Date: 21/05/30 Time: 11:13 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> ${pageContext.request}<br> <h4>在jsp页面动态获取虚拟目录</h4> ${pageContext.request.contextPath}<br> </body> </html>
标签:str esc port object get ons content objects 页面
原文地址:https://www.cnblogs.com/dss-99/p/14827534.html