block jsp page using javascript - Stack Overflow

how to block a jsp page (i want is ,when I click the links to redirect each pages I want to block some

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
Add a ment  | 

4 Answers 4

Reset to default 4

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./">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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742254609a4409792.html

相关推荐

  • block jsp page using javascript - Stack Overflow

    how to block a jsp page (i want is ,when I click the links to redirect each pages I want to block some

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信