简体   繁体   中英

Displaying database table on jsp

I have a login table with the following attributes:

UName Password id FirstName LastName Category DateOfBirth Address EmailId ContactNo AffiliateGroup

sathya///###///////////////////////////////////////////////////Admin

Harish///###/////////001///////////////////////////////////Affiliate

Vinod///###/////////002////////////////////////////////Client//////////////////////////////////////////////////////////////////////////////Harish

Rahul///###/////////003////////////////////////////////Client//////////////////////////////////////////////////////////////////////////////Harish

Radha/###/////////004//////////////////////////////Affiliate

Raaj///###/////////005//////////////////////////////client/////////////////////////////////////////////////////////////////////////////////// Radha

The above is just an illustration of the login table which we are using in our web application.

Explaination : we have an admin, affiliates and clients, There are plenty of registration requests. If its for the position of affiliates then admin handles it. and if its for a position of clients affiliates handle it. There are multiple affiliates and they can add their own clients when they add clients their name gets stored in the database against each client details. Now based on the Affiliates name the clients details should be displayed on the jsp. Above code displays all clients details for all the affiliates but what i want is only his(affiliate) group details must be displayed on jsp..

Here in the above table when Harish logs in only Vinod and Rahul's details must be accessible to him.ie it should be displayed on jsp.

i have tried doing this:

<table id="admclientprofile">

        <tr>
            <th><b>id</b></th>
            <th><b>FirstName</b></th>
            <th><b>LastName</b></th>
            <th><b>Gender</b></th>
            <th><b>Category</b></th>
            <th><b>DateOfBirth</b></th>
            <th><b>Age</b></th>
            <th><b>Address</b></th>
            <th><b>Country</b></th>
            <th><b>State</b></th>
            <th><b>City</b></th>
            <th><b>PinCode</b></th>
            <th><b>UserName</b></th>
            <th><b>EmailId</b></th>
            <th><b>ContactNo</b></th>
            <th><b>MobileNo</b></th>
            <th><b>Status</b></th>
        </tr>


        <c:forEach items="${clients}" var="client">
            <tr>
                <td><c:out value="${client.id}" /></td>
                <td><c:out value="${client.firstName}" /></td>
                <td><c:out value="${client.lastName}" /></td>
                <td><c:out value="${client.gender}" /></td>
                <td><c:out value="${client.category}" /></td>
                <td><c:out value="${client.date}" /></td>
                <td><c:out value="${client.age}" /></td>
                <td><c:out value="${client.address}" /></td>
                <td><c:out value="${client.country}" /></td>
                <td><c:out value="${client.state}" /></td>
                <td><c:out value="${client.city}" /></td>
                <td><c:out value="${client.pinCode}" /></td>
                <td><c:out value="${client.userName}" /></td>
                <td><c:out value="${client.emailId}" /></td>
                <td><c:out value="${client.contactNo}" /></td>
                <td><c:out value="${client.mobileNo}" /></td>
                <td><a href="RejectProfileServlet?id=${client.id}">Reject</a></td>

            </tr>
        </c:forEach>

using the above code, If harish logs in he is able to see all the clients details. But i dont want that to happen harish must be able to view only rahul and vinods data.

Affiliate Group is got by doing : request.getSession.getAttribute("user"); and then inserting it into the database. it is not present in the DTO.

Please help me fix this. Thanks in advance.

This would show only clients from logged in user, but filtered by affiliates name. It wouldn't work if you have multiple clients with the same name. In that case you should compare affiliates by id.

<!-- Some affiliate data -->

<c:forEach items="clients" var="client">

    <c:if test="${client.affiliateName ==  request.getSession().getAttribute("user")}">    

        <!-- Some client data -->

    </c:if>

</c:forEach>

First sort your list by username (Affiliate) and than put code something like this..

<c:forEach items="${clients}" var="client">
    <c:set var="previousAffiliate" scope="page" value="${client.Affiliate}"/>
    <c:if test="${client.Affiliate != previousAffiliate}">
        <tr><c:out value="${client.Affiliate}" /></tr>
    </c:if>
    <tr>
        <td><c:out value="${client.id}" /></td>
        <td><c:out value="${client.firstName}" /></td>
        <td><c:out value="${client.lastName}" /></td>
        <td><c:out value="${client.gender}" /></td>
        <td><c:out value="${client.category}" /></td>
        <td><c:out value="${client.date}" /></td>
        <td><c:out value="${client.age}" /></td>
        <td><c:out value="${client.address}" /></td>
        <td><c:out value="${client.country}" /></td>
        <td><c:out value="${client.state}" /></td>
        <td><c:out value="${client.city}" /></td>
        <td><c:out value="${client.pinCode}" /></td>
        <td><c:out value="${client.userName}" /></td>
        <td><c:out value="${client.emailId}" /></td>
        <td><c:out value="${client.contactNo}" /></td>
        <td><c:out value="${client.mobileNo}" /></td>
        <td><a href="RejectProfileServlet?id=${client.id}">Reject</a></td>

    </tr>
</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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM