replace JSP scriplet code

replace JSP scriplet code with JSTL Tags
--
JSP scriplet code:

<%@ page import="java.util.*, com.luv2code.web.jdbc.*" %>
<!DOCTYPE html>
<html>
<head>
    <title>Student Tracker App</title>
    <link type="text/css" rel="stylesheet" href="css/style.css">
    
</head>
<%
    // get student from the request object (sent by servlet)
    List<Student> theStudents = 
                (List<Student>) request.getAttribute("STUDENT_LIST");
    
%>
<body>
    <div id="wrapper">
        <div id="header">
            <h2>FooBar University</h2>
        </div>
    </div>
    <div id="container">
        <div id="content">
            <table>
                <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Email</th>
                </tr>
                <% for (Student tempStudent: theStudents) { %>
                    <tr>
                        <td><%= tempStudent.getFirstName() %></td>
                        <td><%= tempStudent.getLastName() %></td>
                        <td><%= tempStudent.getEmail() %></td>
                    </tr>
                <% } %>
            </table>
        </div>
    </div>
</body>
</html>

--
replace it with JSTL Tags

  • 首先檢查,library里面有jsp.jstl 和jsp.jstl-api 這兩個jar文件,如圖:
image.png
  • 檢查完之后修改list-students.jsp 代碼如下:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html>
<html>
<head>
    <title>Student Tracker App</title>
    <link type="text/css" rel="stylesheet" href="css/style.css">
    
</head>

<body>
    <div id="wrapper">
        <div id="header">
            <h2>FooBar University</h2>
        </div>
    </div>
    <div id="container">
        <div id="content">
            <table>
                <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Email</th>
                </tr>
                <c:forEach var="tempStudent" items="${STUDENT_LIST}">
                
                    <tr>
                        <td> ${tempStudent.firstName}</td>
                        <td> ${tempStudent.lastName}</td>
                        <td> ${tempStudent.email}</td>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
</body>
</html>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現,斷路器,智...
    卡卡羅2017閱讀 136,536評論 19 139
  • 背景 一年多以前我在知乎上答了有關LeetCode的問題, 分享了一些自己做題目的經驗。 張土汪:刷leetcod...
    土汪閱讀 12,899評論 0 33
  • afinalAfinal是一個android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,857評論 2 45
  • 堵車時 真有一種棄車逃跑的沖動 沖動是魔鬼啊 要不然呢? 還能飛過去嗎? 這個嘛~ 上天不行 入地還是可以的 【在...
    葵普云生產閱讀 471評論 0 0
  • 女媧氏煉石補天之時,于大荒山無稽崖練成高經十二丈,方經二十四丈頑石三萬六千五百零一塊。媧皇氏只用了三萬六千五百塊,...
    胡玖閱讀 233評論 1 0

友情鏈接更多精彩內容