0

I checked this question, and I know how to get and check user role in java.

But, what I want is, when user clicks some links in page, if user has no right on that, how can I get it and return some message like "no rights" in a message fields? Currently, there will be an exception.

I didn't use spring tags in page, I know the tags that display this link if only user has some role. But I don't want to user those tags for some reasons.

Community
  • 1
  • 1
Mavlarn
  • 3,807
  • 2
  • 37
  • 57

1 Answers1

0

You can use JavaScript, handle the click event on the link and see the server response. If it's not ok - show error message. If it is OK - redirect.

Something like this:

$('#your-link-id').click(function(event) {
    event.preventDefault();
    var url = $(this).attr('href');

    $.ajax({
        url : url,
        success : function() {
            window.location = url;
        },
        error : function() {
            alert('You cannot go to this link.');
        }
    });
});

(jQuery library is used).

weekens
  • 8,064
  • 6
  • 45
  • 62