how to block a jsp page (i want is ,when I click the links to redirect each pages I want to block some specific pages for specific users) I create an java script function to retrieve the jsp pages of each users(pages that user can access).But I have no idea to block other pages for the same user)
use js document.getElementById("id name of link").style.display = 'none';
to remove the link from page and use 'block' instead of 'none' for showing the link.
You could use the event.preventDefault();
and have a variable saying if the user should or not be blocked. Check the following example:
var BlockUser = true;
function CheckUser() {
if ( BlockUser ) {
event.preventDefault();
}
}
<a href="http://stackoverflow.com/">Link for any user</a>
<br>
<a href="http://stackoverflow.com/" onclick="CheckUser()">Link for certain users</a>
Pure jsp solution:
assuming you have an array of available links: List<String> links
, which you pass under the same name to request(or you may retrieve it from user, doesn't matter, assume you have array of those links despite way of getting it), then you can do something like:
...
<c:forEach var="link" items="${links}">
<a href="${link}" <c:if test="/*here you test if user have
access, i dont know how you do it*/"> class="inactiveLink" </c:if>>page link</a>
</c:forEach>
...
Where ...
is rest of your jsp, and define style
.inactiveLink {
pointer-events: none;
cursor: default;
}
Note that in order to use foreach - you should define jstl taglib at the top of your jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
In case you don't know what is jstl, and what is EL generally
A good notion was said about disabling css and js, if you want them to be completely inaccessible, you can just print only allowed links:
...
<c:forEach var="link" items="${links}">
<c:if test="/*here you test if user have
access, i dont know how you do it*/">
<a href="${link}">page link</a>
</c:if>
</c:forEach>
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With