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

标签 java html mysql jsp

这是我的带有删除按钮的jsp代码。我不想删除当前登录用户。 这是我的带有删除按钮的jsp代码。我不想删除当前登录用户。

<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

最佳答案

你可以这样做:

    <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>

逻辑是,如果当前用户 ID 等于列表中的用户 ID,则不显示删除按钮。

关于java - 如何防止在JSP页面或HTML中删除当前登录用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24361419/

相关文章:

Java super 和 this 关键字

java - 按钮组如何更改 JCheckBox 的计数

PHP/MySQL 多重嵌套 SELECT

php - 为空白的 LEFT JOIN 设置 0 结果?

java - 返回java中的对象名

java - 在没有互联网的情况下,需要更多时间从类路径加载 spring-*.xsd 文件

html - 如何添加下拉菜单?

css - 将子 div 在父级中居中/底部对齐

javascript - Bootstrap 轮播 - 将 <video> 垂直对齐在 div 中间

PHP 从传递的变量构建 MySQL 查询字符串