栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java web

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java web

文章目录

一._ EL _

1.做运算2.el表达式只能从域对象中获取值3.获取对象 list集合,map集合的值

1.对象:$ {域名称.键名.属性名}2.list集合:$ {域名称.键名[索引]}3.map集合 二.JSTL

1.foreach2.choose(相当于switch)3.if 三.三层架构

一._ EL _

作用:替换和简化jsp页面中java代码的编写
语法:${表达式}

1.做运算

${3>4} 结果为false
${6+7} 结果为13

2.el表达式只能从域对象中获取值

语法:
1.$ {域名称.键名}:从指定域中获取指定键的值
域名称:pageScope --> pageContext
举例:在request域中存储了name=张三
获取:$ {requestScope.name}

<%--
  Created by IntelliJ IDEA.
  User: cll
  Date: 2022/1/21
  Time: 13:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

  
    Title

  
  <%
    request.setAttribute("name","李四");
  %>
  ${requestScope.name};



显示:

李四;

2.{键名}:表示依次从最小的域中查找是否有该键对应的值,直到找到为止

%--
  Created by IntelliJ IDEA.
  User: cll
  Date: 2022/1/21
  Time: 13:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

  
    Title

  
  <%
    session.setAttribute("name","李四");

    request.setAttribute("name","张三");

  %>
     ${name};




显示:

张三;
3.获取对象 list集合,map集合的值 1.对象:$ {域名称.键名.属性名}

本质上会去调用对象的getter方法

package com.kuang.pojo;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Userel {
    private String name;
    private int age;
    private Date birthday;
    public String getBitStr(){
        if(birthday!=null){
            //格式化日期对象
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return simpleDateFormat.format(birthday);
        }
        else{
            return "";
        }
    }
    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;
    }
}

<%@ page import="com.kuang.pojo.Userel" %>
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: cll
  Date: 2022/1/21
  Time: 13:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

  
    Title

  
  <%
    Userel user=new Userel();
    user.setName("张三");
    user.setAge(19);
    user.setBirthday(new Date());
    request.setAttribute("u",user);

  %>
  <%-- --%>
     ${u.age}
${requestScope.u.name}
  ${u.birthday}
  ${u.bitStr}



19 张三 Fri Jan 21 15:02:26 CST 2022 2022-01-21 15:02:26
2.list集合:$ {域名称.键名[索引]}
<%@ page import="com.kuang.pojo.Userel" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %><%--
 Created by IntelliJ IDEA.
 User: cll
 Date: 2022/1/21
 Time: 13:20
 To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

 
   Title

 
 <%
   Userel user=new Userel();
   user.setName("张三");
   user.setAge(19);
   user.setBirthday(new Date());
   request.setAttribute("u",user);
   List list=new ArrayList();
   list.add("aaa");
   list.add("ccc");
   list.add("kkk");
   list.add(user);
   request.setAttribute("list",list);

 %>
 <%-- --%>
    ${list}
   ${list[1]}
 ${list[0]}
 ${list[3].name}


显示:

[aaa, ccc, kkk, com.kuang.pojo.Userel@1342c24] ccc aaa 张三
3.map集合

${域名称.键名.key名称}
${域名称.键名[“key名称”]}

<%@ page import="com.kuang.pojo.Userel" %>
<%@ page import="java.util.*" %><%--
  Created by IntelliJ IDEA.
  User: cll
  Date: 2022/1/21
  Time: 13:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

  
    Title

  
  <%
    Userel user=new Userel();
    user.setName("张三");
    Map map=new HashMap();
    map.put("name","李四");
    map.put("age",18);
    map.put("user",user);
    request.setAttribute("map",map);

  %>
  <%-- --%>
${map.name}
  ${map.age}
  ${map.user.name}



显示:

李四 18 张三
二.JSTL 1.foreach
<%@ page import="com.kuang.pojo.Userel" %>
<%@ page import="java.util.*" %><%--
  Created by IntelliJ IDEA.
  User: cll
  Date: 2022/1/21
  Time: 13:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

  
    Title

  
  <%
    List list=new ArrayList();
    list.add("aaa");
    list.add("bbb");
    list.add("ccc");
    request.setAttribute("list",list);
  %>
  <%-- --%>

  ${s.index} ${s.count} ${str} 
0 1 aaa
1 2 bbb
2 3 ccc
 
    ${i} ${s.index} ${s.count}
1 1 1
3 3 2
5 5 3
7 7 4
9 9 5
2.choose(相当于switch)
<%
request.setAttribute("number",5);
%>

    星期一
    星期二
    星期三
    星期四
    星期五
    星期六
    星期天
    数字输入有误
  

星期五
3.if
<%
request.setAttribute("number",5);
%>

    

${number}为奇数
我
5为奇数
<%@ page import="com.kuang.pojo.Userel" %>
<%@ page import="java.util.*" %><%--
  Created by IntelliJ IDEA.
  User: cll
  Date: 2022/1/21
  Time: 13:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

  
    Title

  
  <%
    List list=new ArrayList();
    list.add(new Userel("张三",18,new Date()));
    list.add(new Userel("李四",19,new Date()));
    list.add(new Userel("王五",20,new Date()));
    request.setAttribute("list",list);
  %>
  <%-- --%>
  
      
        
        
编号 姓名 年龄 生日
${s.count} ${user.name} ${user.age} ${user.birStr}
${s.count} ${user.name} ${user.age} ${user.birStr}

三.三层架构


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/713202.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号