On the usage of traversing set attributes with jstl Tags

  in MVC Model, Model or Map is usually used to store Model data in Request domain or Session domain, so that the Model data put in the back-end controller can be obtained from the front-end page of WEB project. The set attributes often need to be rendered into a table form on the page. The following record is about the usage of rendering set attributes to tables on the front-end page:
1. Add the jar package required by JSTL: jstl-1.2.jar and standard-1.1.2.jar. Since SpringMVC is more used, it seems that Struts2 is self-contained.
2. Introduce jstl label to the page:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3. Loop through with Tags:
<c:if test="${empty requestScope.emps}">
    No employee information!
<c:if test="${!empty requestScope.emps}">
    <table border="1" cellpadding="10" cellspacing="0">
        <!--Loop through set properties,among items Is get collection, var It is to take an alias for the acquired set, which is convenient for writing-->
        <c:forEach items="${requestScope.emps}" var="employees">
                <td align="center">${employees.lastName}</td>
                <!--Judgement and analysis-->
                <td align="center">${employees.gender == 0 ? 'female' : 'male'}</td>
                <td align="center">${employees.department.departmentName}</td>
                <td><a href="">Edit</a> </td>
                <td><a href="">Delete</a> </td>

[note] the above is to put the set of Employee types queried into the Request domain, where there are several attributes to be explained in the Employee: the gender attribute is Integer type, 0 represents female, 1 represents male, and department represents the Department of the Employee (many to one Association).

Tags: Session Java JSP Attribute

Posted on Wed, 01 Apr 2020 11:39:34 -0700 by Undrium