JavaWeb-簡析EL表達式

6.1EL表達式:${}

pom.xml依賴:

<!--Jstl表達式依賴-->
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl-api -->
<dependency>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>jstl-api</artifactId>
    <version>1.2</version>
</dependency>

<!--standard標籤庫-->
<!-- https://mvnrepository.com/artifact/taglibs/standard -->
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>

功能:

- 獲取數據。

- 執行運算。

- 獲取Web開發的常用對象。

Jsp標籤:

<%--jsp:include 之前列舉過了--%>
<%--生成的網頁會爲:http://localhost:8080/jsptag.jsp?name=Edwin_Duan&age=17 --%>
<%--jsp:forward,跳槽頁面--%>
<jsp:forward page="/jsptag2.jsp">
    <%--jsp:param,設置變量和值。--%>
    <jsp:param name="name" value="Edwin_Duan"/>
    <jsp:param name="age" value="17"/>
</jsp:forward>

代碼測試:

Jsptag.jsp:

<%--
  Created by IntelliJ IDEA.
  User: 元
  Date: 2020.6.9
  Time: 上午 11:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Tag</title>
</head>
<body>
    <h1>Tag1</h1>
<%--jsp:include 之前列舉過了--%>
    <%--生成的網頁會爲:http://localhost:8080/jsptag.jsp?name=Edwin_Duan&age=17 --%>
    <%--jsp:forward,跳槽頁面--%>
    <jsp:forward page="/jsptag2.jsp">
        <%--jsp:param,設置變量和值。--%>
        <jsp:param name="name" value="Edwin_Duan"/>
        <jsp:param name="age" value="17"/>
    </jsp:forward>

</body>
</html>

Jsptag2.jsp:

<%--
  Created by IntelliJ IDEA.
  User: 元
  Date: 2020.6.9
  Time: 上午 11:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Tag2</title>
</head>
<body>
    <h1>Tag2</h1>
    <%--取出參數--%>
    Name:<%= request.getParameter("name")%>
    Age:<%= request.getParameter("age")%>

</body>
</html>

申請訪問jsptag.jsp:

在這裏插入圖片描述

《成功的花》——冰心
成功的花,
人們只驚羨她現時的明豔!
然而當初她的芽兒,
浸透了奮鬥的淚泉,
灑遍了犧牲的血雨!

參考文獻

《【狂神說Java】JavaWeb入門到實戰》

視頻連接

2020.06.09

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章