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

  • Home
  • SEARCH
  • 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 477077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:33:16+00:00 2026-05-13T00:33:16+00:00

I have tried to find the answer to this question on both the Spring

  • 0

I have tried to find the answer to this question on both the Spring forum and by searching StackOverflow. I have found a lot of pages describing horrible architectures and asking for about the same thing as I do, but my intended usage is different so please bear with me 🙂

I have a Spring 2.5 project using annotation based form controllers basically like this:

@RequestMapping("/edit/someObject")
public String handleSubmit(HttpServletRequest request, HttpServletResponse response, SomeObject someObject, BindingResult result) {

    // Some check here

    if(result.hasErrors()) {
        return "form";
    } else {
        SomeObjectService.update(someObject);
        return "redirect:/view/someObject";
    }
}

In this I check for some http property in the HttpServletRequest and use the HttpServletResponse to send a redirect if this property has a certain value. This check is done is a lot (but not all) of the form controllers in this application. What I would like to do is create a @CheckedSubmit annotation handled by some AOP advice to do this check and then drop the HttpServletRequest and HttpServletResponse parameters from the controller.

My problem is that I have no idea how to access the current HttpServletRequest and HttpServletResponse from this AOP advice without using these two as (unused) parameters to the annotated method, which is what I tried to avoid in the first place.

Summary: How to access the HttpServletRequest/Response from AOP advice on an @RequestMapping annotated method?

  • 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-13T00:33:17+00:00Added an answer on May 13, 2026 at 12:33 am

    Two solutions for the summary but not for your entire problem (completely)

    Solution 1: inside advice (>= Spring 2.0 required)

    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes()).getRequest();
    

    Solution 2: inside aspect class (probably Spring 3.0 inside singelton beans required!)

    @Autowired(required=true)
    private HttpServletRequest request;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to find answer to this question from the official docs, but
I have stupid question, on which can't find answer. I tried to install Selenium
Frstly my apologies if this is a duplicate question. I have tried to find
I've tried Google, but I can't find the answer to this simple question. I
So I have tried to find a answer but must not be searching correctly
Have tried to find solutions for this and can't really come up with anything.
I have found many similar posts and even tried to find out how to
I have searched a lot and tried much but I can not find the
I tried searching and didn't find anything that fixed my problem. I have a
Here's a dumb question which I can't find an answer to: I have a

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.