简体   繁体   English

如何防止在JSP页面或HTML中删除当前登录用户

[英]how to prevent deletion of current log in user in JSP page or HTML

This is my jsp code with delete button. 这是我的带有删除按钮的jsp代码。 I dont want to delete current login user. 我不想删除当前的登录用户。 This is my jsp code with delete button. 这是我的带有删除按钮的jsp代码。 I dont want to delete current login user. 我不想删除当前的登录用户。

<table border="1">
                <thead style="background: #0086B2;">
                    <tr>
                        <th></th>
                        <th>Sl No.</th>
                        <th>User Name</th>
                        <th>Phone Number</th>
                        <th>Email Id</th>
                        <th>Login Id</th>

                    </tr>
                </thead>
                <c:if test="${userList!=null}">
                    <c:forEach items="${userList}" var="user">
                        <tr>
                            <td><input type="checkbox" name="deleteVal"
                                value="${user.slNo}"></td>
                            <td>${user.slNo}</td>
                            <td>${user.userName}</td>
                            <td>${user.emailId}</td>
                            <td>${user.phoneNumber}</td>
                            <td>${user.loginId}</td>
                        </tr>
                    </c:forEach>
                </c:if>
            </table>
            <br>
            <table>
            <tr>
                <td><input type="button" value="Delete"></td>
                            <tr>
                           </table

You can do something like this: 您可以执行以下操作:

    <table border="1">
        <thead style="background: #0086B2;">
            <tr>
                <th></th>
                <th>Sl No.</th>
                <th>User Name</th>
                <th>Phone Number</th>
                <th>Email Id</th>
                <th>Login Id</th>
                <th>Delete</th>
            </tr>
        </thead>
        <c:if test="${userList!=null}">
            <c:forEach items="${userList}" var="user">
                <tr>
                    <td><input type="checkbox" name="deleteVal"
                        value="${user.slNo}"></td>
                    <td>${user.slNo}</td>
                    <td>${user.userName}</td>
                    <td>${user.emailId}</td>
                    <td>${user.phoneNumber}</td>
                    <td>${user.loginId}</td>
                <c:if test="${user.slNo != (User Id from session)}"> 
                       <td><input type="button" value="Delete" 
                            onclick="delete(${user.slNo})"></td>
                  </c:if>
            </c:forEach>
        </c:if>
    </table>

Logic is that if current user ID equals the user ID in the list , then don't show the delete button. 逻辑是,如果current user ID equals the user ID in the list则不显示删除按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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