zoukankan      html  css  js  c++  java
  • jsp二(指令)

    一、jsp动作标签:

    1)<jsp:forward> 请求转发 相当于之前的request.getRequestDispatcher(..).forward(..);

    1 <!--jsp转发-->
    2 <jsp:forward page="2.jsp"></jsp:forward>

    2)<jsp:include> jsp动态包含。<%include %>jsp的静态包含。

    1 <jsp:include page="1.jsp"></jsp:include>
    2 <jsp:include page="2.jsp"></jsp:include>

    动态包含:是将被包含的jsp编译执行的结果插入包含的页面中,每个被包含的jsp都会生活一个java和class文件。

    而静态包含只是生成一份包含的jsp的java和class页面。

     二)el表达式

    1、jsp的内置表达式语言是jsp2.0开始。

    用来代替<%=%>

    作用:

      1)获取域中的数据。☆便捷的方法${xxx}

      2)执行运算

      3)获取常见的web对象。

      4)调用java方法。

    格式:

      ${el表达式}:以${开始以}结束。

    获取域中的数据:

    需要注意的是,如果直接不指定域的话,查找的顺序就是从Page 再然后从Request、Session、Application一次查找

    找到之后就停止。不会继续查找,如果没找到的话返回的null 但是el表达式是直接显示的空白。

    获取数组:

    格式:定义的名字[index]

    获取List:

    格式:定义的名字[index]

    获取Map:

    格式:定义的名字[键的名字]

    获取特殊的名字,比如名字里有"."|"+"|"-"等。使用对应的el的变量xxscope["特殊的名字"]

     1 <%@ page import="java.util.List" %>
     2 <%@ page import="java.util.ArrayList" %>
     3 <%@ page import="java.util.Map" %>
     4 <%@ page import="java.util.HashMap" %>
     5 
     6 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
     7 <html>
     8 <head>
     9     <title>Title</title>
    10 </head>
    11 <body>
    12 <%
    13 //获取复杂数据:数组、list、map
    14     request.setAttribute("array",new String[]{"a","c"});
    15     List list=new ArrayList();
    16     list.add("c");
    17     list.add("d");
    18     request.setAttribute("list",list);
    19     Map map=new HashMap();
    20     map.put("oop","java");
    21     map.put("test","oop");
    22     request.setAttribute("map",map);
    23     //获取特殊的名字的
    24     request.setAttribute("map.age","112");
    25 %>
    26 //获取数组
    27 
    28 //旧方式
    29 <%=((String[]) (request.getAttribute("array")))[1]%>
    30 //el方式
    31 ${array[1]}
    32 <hr>
    33 //获取list
    34 
    35 //旧方式
    36 <%=((List)request.getAttribute("list")).get(1)%>
    37 //el方式
    38     ${list[1]}
    39 <hr>
    40 //获取map
    41 
    42 //旧方式
    43 <%=((Map)request.getAttribute("map")).get("oop")%>
    44 //el方式
    45 ${map["oop"]}
    46 <hr>
    47 //获取特殊名字
    48 ${requestScope["map.age"]}
    49 </body>
    50 </html>
  • 相关阅读:
    网站性能之meta标签
    布局中的css要素
    MVC中配置OutputCache的VaryByParam参数无效的问题
    C# 4.0 类与继承
    想要充值手机话费吗???亿矿网找错误送话费啦
    .Net Core 依赖注入
    Hadoop实战内容摘记
    Thead,TheadPool,Task,async,await 的前世今生
    VS Code 中 使用 Git版本控制工具
    dotnet 命令大全-理论版
  • 原文地址:https://www.cnblogs.com/evilliu/p/8617431.html
Copyright © 2011-2022 走看看