question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Java][Spring] How to inject HttpServletResponse in controller

See original GitHub issue

Is is possible to inject a HttpServletResponse in a generated controller method?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

4reactions
Btorkoycommented, Aug 12, 2020

try it: HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();

3reactions
imodcommented, Apr 7, 2020

as a workaround: you can inject HttpServletResponse and HttpServletRequest into the constructor of your controller. Spring will take care of scoping and make the correct objects available for you at execution time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Spring Boot inject same HttpServletResponse object to ...
The servlet container creates an HttpServletResponse object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).
Read more >
Access HttpServletRequest and HttpServletResponse in ...
In this tutorial, I would like to share with you all how to access HttpServletRequest and HttpServletResponse in Spring MVC controller.
Read more >
How to Set a Header on a Response with Spring 5 - Baeldung
We simply have to add the HttpServletResponse object to our REST endpoint as an argument, and then use the addHeader() method:.
Read more >
17.Accessing HttpServletRequest and HttpServletResponse in ...
In this video we will explore how to Access HttpServletRequest and HttpServletResponse in Spring MVC handler method.
Read more >
Why Spring Boot inject same HttpServletResponse object to ...
[Solved]-Why Spring Boot inject same HttpServletResponse object to my Controller method for different request?-Springboot ... Finally, i find Response will been ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found