0

I would like to handle request and session attributes myself rather than leaving it to Spring @SessionAttributes, for login or cookies handling for example. I just cannot figure out how to access the HttpRequest from within a controller. I need a way to go a layer above the @RequestAttribute and access the HttpRequest itself. With Stripes in used to do this by implementing an ApplicationContext and calling getAttribute().

Also, passing the HttpServletRequest as parameter seems not to work:

@RequestMapping(value="/")
public String home(HttpServletRequest request){   
    System.out.println(""+request.getSession().getCreationTime());
    return "home"; 
}

Why does this method not print anything?

1 Answer 1

1

Attach a debugger and confirm that your controller method is called.

Check the following:

  1. Are you sending a POST request? Then you need to specify the method name with the method parameter: @RequestMapping(value = "/hello", method = RequestMethod.POST)

  2. Is your controller properly detected by Spring via the @Controller annotation?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.