Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6804587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:29:04+00:00 2026-05-26T19:29:04+00:00

I have the same exact question as here, except that the answer doesn’t make

  • 0

I have the same exact question as here, except that the answer doesn’t make sense to me.

Spring Security Access Denied Handler – how do you determine what the URL was that the user tried to access?

I tried to follow what they were saying in their answer by creating this:

@RequestMapping("/invalidPermission")
public void invalidPermission(HttpServletRequest request) {
  System.out.println(request.getServletPath());
}

However, the request.getServletPath() will obviously print out /invalidPermission instead of the original url they attempted to access.

Any ideas?

Thanks!

Update: Here’s the working code

<access-denied-handler ref="FooAccessDeniedHandler" />
<bean id="FooAccessDeniedHandler"
     class="my.pkg.AccessDeniedExceptionHandler">
  <property name="errorPage" value="/path-to/custom403.jsp" />
</bean>

package my.pkg.AccessDeniedExceptionHandler;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

public final class AccessDeniedExceptionHandler implements AccessDeniedHandler {

    private String errorPage;

    @Override
    public void handle(final HttpServletRequest request, final HttpServletResponse response, final AccessDeniedException arg2) throws IOException, ServletException {
        System.out.println(String.format("URL [%s] ", request.getServletPath()));
        response.sendRedirect(getErrorPage());
    }

    public String getErrorPage() {
        return errorPage;
    }

    public void setErrorPage(String errorPage) {
        this.errorPage = errorPage;
    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:29:05+00:00Added an answer on May 26, 2026 at 7:29 pm

    In that answer they were using the handle() method of a custom AccessDeniedHandler, not a controller action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically have the exact same problem as here: http://stackoverflow.com/questions/2416155/issue-in-executing-spring-web-project-in-eclipse-on-tomcat-server but the fix for
I have the same question problem as described here How to purge a cached
I have three different tables that have the exact same style rules applied to
This question contains java and ruby. I have a java program that I make
I asked Almost this exact same question yesterday. Basically I have a css button
I have two enumerables with the exact same reference elements, and wondering why Equals
I have the same problem as described in the posts listed below. That is,
I have the same question as #1895500 , but with PostgreSQL not MySQL. How
i have a small question concerning away3D. I have some cubes with the exact
Here is the situation, i have a website that can be accessed from multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.