zoukankan      html  css  js  c++  java
  • EL表达式基础

    <%@ page language="java" pageEncoding="utf-8" import="com.study.vo.*,java.util.*" %>
    <html>
        <head>
        
        </head>
        <body>
            <h2>使用普通方法获得作用域对象</h2>
            <b><%=request.getParameter("name")%></b><br/>
            <b><%=request.getAttribute("str")%></b><br/>
            <b><%=((User)request.getAttribute("user")).getAddress().getAddr()%></b><br/>
            <b><%=((ArrayList<User>)request.getAttribute("list")).get(0).getAddress().getAddr() %></b><br/>
            <b><%=((HashMap<String,User>)request.getAttribute("map")).get("user").getAddress().getAddr()%></b>
            <hr/>
            <h2>使用EL表达示获得作用域对象(优点:不用导包,阅读方法,代码更少)</h2>
            <b>${param.name}</b><br/>
            <b>${str}</b><br/>
            <b>${user.address.addr}</b><br/>
            <b>${list[0].address.addr}</b><br/>
            <b>${map.user.address.addr}</b><br/>
            
            <h2>EL表达式获取对象默认顺序</h2>
            <%
                pageContext.setAttribute("hello","pagecontext");
                request.setAttribute("hello","request");
                session.setAttribute("hello","session");
                application.setAttribute("hello","application");
            %>
            <b>pageContext-->request-->session-->application</b><br>
            <b>${pageScope.hello}</b><br>
            <b>${requestScope.hello}</b><br>
            <b>${sessionScope.hello}</b><br>
            <b>${applicationScope.hello}</b><br>
            <h2>EL表达式的算术运算</h2>
            <strong>不支持字符串连接</strong><br/>
             ${1+2}--${1-2}--${1>2}--${1==2?0:0}--${1+"2"}
             <h2>判断是否为空</h2>
             <b>${empty str}</b>
             <b>${empty test}</b>
             <h2>获得请求头数据 heard(了解)</h2>
             <b>${header }</b><br>
             <b>${header["cookie"] }</b><br>
             <b>${headerValues["cookie"]}</b>
             <h2>获得cookie数据</h2>
             <b>${cookie }</b><br>
             <b>${cookie.JSESSIONID }</b><br>
             <b>${cookie.JSESSIONID.name }</b><br>
             <b>${cookie.JSESSIONID.value }</b><br>
        </body>
    </html>
        @Override
        public void service(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
            request.setCharacterEncoding("utf-8");
            response.setContentType("text/html;charset=utf-8");
            request.setAttribute("str","javase");
            User u=new User(1, "javase", "javaee", "javame", new Address("china"));
            request.setAttribute("user",u);
            List<User> list=new ArrayList<User>();
            list.add(u);
            request.setAttribute("list", list);
            Map<String,User> map=new HashMap<String,User>();
            map.put("user",u);
            request.setAttribute("map",map);
            request.getRequestDispatcher("/ELStudy.jsp").forward(request, response);
        }
  • 相关阅读:
    js 性能调试
    js 面向对象编程
    js 零碎
    如果遇到二维数组 想取某个字段的和
    昨天写支付接口时遇到支付接口返回数据接收地址,session数据丢失(或者说失效)的问题
    mysql报错: 1548-Cannot load from mysql.proc. The table is probably corrupted 解决办法
    php 时间倒计时代码 个人写法 有好的想法的欢迎贴出来分享
    linux 环境下安装mysql5.6
    关于数据库连接不上 出现错误的问题
    推荐一个不错的css3网站 可以直接调用的
  • 原文地址:https://www.cnblogs.com/lastingjava/p/9899032.html
Copyright © 2011-2022 走看看