Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

block jsp page using javascript

Tags:

javascript

jsp

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)

like image 774
chamzz.dot Avatar asked Feb 20 '17 15:02

chamzz.dot


3 Answers

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.

like image 168
sanjeewa kumara Avatar answered Oct 16 '22 19:10

sanjeewa kumara


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>
like image 3
user7393973 Avatar answered Oct 16 '22 17:10

user7393973


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>
...
like image 2
Dmytro Grynets Avatar answered Oct 16 '22 19:10

Dmytro Grynets