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)
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)
Share Improve this question asked Feb 20, 2017 at 15:08 chamzz.dotchamzz.dot 7752 gold badges12 silver badges25 bronze badges 3- Does the solution has to be in jsp, or do you accept it if it's all in javascript? – user7393973 Commented Feb 20, 2017 at 15:14
- I prefer in any of these languages – chamzz.dot Commented Feb 20, 2017 at 15:15
- Check out my answer and let me know if it helped or not. – user7393973 Commented Feb 20, 2017 at 15:25
4 Answers
Reset to default 4use 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./">Link for any user</a>
<br>
<a href="http://stackoverflow./" 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./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 pletely 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>
...
You can use this
document.getElementById( "id of your link element" ).style.display = 'none';
style.display
is use for not displaying anything by setting it to none