我的程序從輸入中獲取一封電子郵件,并使用 haveibeenpwned API 向用戶顯示從該電子郵件中發現的所有違規行為。我想知道如何讓我的forEach循環正確填充表格。目前,它只是將每個項目填充到一個表格行中,表格標題位于數據下方。我希望標題位于頂部,并且每個違規都位于單獨的表格行中。這是我的 .jsp 表單,顯示了表格和forEach:<table class="table"> <thead> <tr> <th scope="col">#</th> <th scope="col">Breach</th> </tr> </thead> <tbody> <c:forEach var="breach" items="${breaches}" varStatus="status"> <tr> <th scope="row">${status.count}</th> <td><p>${breach}</p></td> </tr> </c:forEach> </tbody></table>這是我的 servlet,我在其中獲得了已發現漏洞的 ArrayList:String json = callPwnedApi(email); if (json.startsWith("{") || json.startsWith("[")) { Gson gson = new Gson(); ArrayList<Breach> breaches = gson.fromJson(json, new TypeToken<ArrayList<Breach>>(){}.getType()); if (!breaches.isEmpty() && breaches.size() > 0) { request.setAttribute("breaches", breaches); } }
2 回答

翻閱古今
TA貢獻1780條經驗 獲得超5個贊
所以作為 JSTL 的新手,我犯了一個非常簡單的錯誤!
我不知道我需要將 JSTL 庫添加到我的項目中,并且我還需要將這一行添加到我的.jsp
頁面中:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
所以在這樣做之后,我的桌子就完美了!希望這最終會幫助那些剛接觸 JSTL 的人!
添加回答
舉報
0/150
提交
取消