I am not used to the JSTL tag library. I learned the basic use of JSTL for loop. But when I start my project I got some complexity. In this stage, I can't figure out how to use JSTL. the JSP page code below.
<%
//get the group list for post
GroupOperation gpo = new GroupOperation(DBConnection.getConnection());
List<Groups> groupList = gpo.getGroups();
pageContext.setAttribute("myGroup", groupList);
//get the user post
PostOperation postOperation = new PostOperation(DBConnection.getConnection());
List<Posts> postList = postOperation.getAllPost();
pageContext.setAttribute("psList", postList);
if (postList == null) {
System.out.println("there is no post to show");
}
%>
<%
for (GroupMembers memgr : grm) {
for (Posts p : postList) {
if (memgr.getGroupId() == p.getGroupId()) {
%>
<h4><%= gpo.getSingleGroup(p.getGroupId()).getGroupName()%></h4>
<%
}
}
}
%>
<%= gpo.getSingleGroup(p.getGroupId()).getGroupName()%> this is my most complexity part. i will always be appreciate for your answere.
First you need to add jstl jar file in your build path. and use following code, I hope it will help you and get some idea
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:forEach items="grm" var="memgr">
<c:forEach items="postList" var="p">
<c:if test="${memgr.groupId eq p.groupId}">
<h4>
${gpo.getSingleGroup(p.getGroupId()).groupName}
</h4>
</c:if>
</c:forEach>
</c:forEach>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.