0

Is this right way to get HttpServletRequest using CDI in a non Bean

HttpServletRequest request = CDI.current().select(HttpServletRequest.class).get();

Edit :

I want to access the HttpServletRequest for logging session session information like username etc.

ravthiru
  • 8,878
  • 2
  • 43
  • 52

1 Answers1

2

To acquire a properly managed instance of the request, do this instead:

@Context
private HttpServletRequest httpRequest;

Source: Injection of HttpServletRequest

Community
  • 1
  • 1
Carlos Laspina
  • 2,013
  • 4
  • 27
  • 44