jsp el expressions and jstl page

 

Note: Due to the long-term back-end code to write code that leads to the front quickly forgotten the basic. Summarize some again later for future use

to sum up:

1: jsp parameters and properties:

      a) Parameters parameter: three sources:

           i: web.xml or annotations provided

           ii: url form submission and set

           iii: Hyperlinks acquired

      B): Attribute: four kinds of range, any optional type. In addition to the javabean property requires its own set manually.

           i:page,request,session,Application

2: el usage:

     A): Simple Type: Range Attribute

      b) class instance: range. Property name. Field name

       c): Array: $ {list [0] .name}

3:jstl:<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

            In use the output jstl <c: out value = "el expression"> </ c: out>

 

 

<%@ page import="com.xm.workflow.entity.TestUser" %>
<%@ page import="net.sf.json.JSONArray" %>
<%@ page import="java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 86156
  Date: 2019/8/15
  Time: 17:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String data = " [{\n" +
            "                \"id\": 839707,\n" +
            "                \"oldFileName\": \"体育-跑酷.png\",\n" +
            "                \"newFileName\": \"eca3b34c-8415-4915-ab9c-68749af6c3ad\",\n" +
            "                \"fileSize\": 1285,\n" +
            "                \"fileType\": \".png\",\n" +
            "                \"createTime\": \"2019-08-12 17:20:43.0\",\n" +
            "                \"swfNum\": 0,\n" +
            "                \"contractId\": 6653,\n" +
            "                \"createUser\": \"lixin5\",\n" +
            "                \"updateUser\": \"lixin5\",\n" +
            "                \"updateTime\": \"2019-08-12 17:20:43.0\",\n" +
            "                \"status\": 0,\n" +
            "                \"fileUrl\": \"http://api.miren.test.mi.com/ua/contractAttach?id\\u003d839707\\u0026newFileName\\u003deca3b34c-8415-4915-ab9c-68749af6c3ad\"\n" +
            "            }]";
    JSONArray jsonArray = JSONArray.fromObject(data);
    request.setAttribute("jsonArray", jsonArray);

    int[] ages = {1, 2, 3, 4, 5}; // 普通数组,JSTL直接使用JSP赋值表达式来取
    List<String> names = new LinkedList<String>(); // List

    names.add("Biao");

    names.add("彪");

    names.add("雷");

    request.setAttribute("names", names); // 添加到request
    Map<String, String> map = new HashMap<String, String>(); // Map

    map.put("1", "黄彪");

    map.put("2", "丫头");

    map.put("3", "哥哥");

    map.put("4", "笨蛋");

    List<TestUser> users = new ArrayList<TestUser>(); // JavaBean的List

    users.add(new TestUser("黄彪", "xxxxxx"));

    users.add(new TestUser("昊天", "xxxxxx"));

    users.add(new TestUser("姐姐", "yyyyyy"));

    users.add(new TestUser("丫头", "zzzzzz"));

    session.setAttribute("users", users); // 添加到session
%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<table border="1">
    <!--遍历数组-->
    <tr>
        <th>aaa</th>
        <c:forEach items="<%=ages%>" var="age">
            <th><c:out value="${age}"></c:out></th>
        </c:forEach>
    </tr>

    <!--遍历list-->
    <tr>
        <c:forEach items="${names}" var="name">
            <th><c:out value="${name}"></c:out></th>
        </c:forEach>
    </tr>
    <!--遍历list2-->
    <tr>
        <c:forEach items="<%=names%>" var="name">
            <th><c:out value="${name}"></c:out></th>
        </c:forEach>
    </tr>
</table>

<!--遍历map-->
<table border="1">

    <tr>

        <th>Key</th>

        <th>Value</th>

    </tr>

    <c:forEach var="entry" items="<%= map %>">

        <tr>

            <td><c:out value="${entry.key}"/></td>

            <td><c:out value="${entry.value}"/></td>

        </tr>

    </c:forEach>

</table>

<table border="1">
    <tr>
        <th>username</th>
        <th>bz</th>
    </tr>
    <c:forEach items="${users}" var="user">
        <tr>
            <th><c:out value="${user.name}"></c:out></th>
            <th><c:out value="${user.bz}"></c:out></th>
        </tr>
    </c:forEach>

</table>

<table border="1">
    <c:forEach items="${jsonArray}" var="entrty">
        <tr>
            <th><c:out value="${entrty.id}"></c:out></th>
        </tr>
        <tr>
            <th><c:out value="${entrty.oldFileName}"></c:out></th>
        </tr>
        <tr>
            <th><c:out value="${entrty.newFileName}"></c:out></th>
        </tr>
        <tr>
            <th><h1>http://jtest.mioffice.cn:8080/mibpm/client/contract/downloadAttachFile?id=+<c:out
                    value="${entrty.id}"></c:out>&uid=<c:out value="${entrty.newFileName}"></c:out></h1></th>
        </tr>
        <tr>
            <th><a target="_blank" href="http://jtest.mioffice.cn:8080/mibpm/client/contract/downloadAttachFile?id=<c:out value="${entrty.id}"></c:out>&uid=+<c:out value="${entrty.newFileName}"></c:out>">点击链接</a>
            </th>

        </tr>
    </c:forEach>
</table>

</body>
</html>

 

Published 57 original articles · won praise 15 · views 40000 +

Guess you like

Origin blog.csdn.net/qq_41694906/article/details/99668114