Spring MVC - the answer
How can I access the response object from the bean? To get the request object, I use the following.
ServletRequestAttributes attr = (ServletRequestAttributes)
RequestContextHolder.currentRequestAttributes();
Is there something similar to the above for the response object?
+2
Viren pushpanayagam
source
to share
1 answer
If you are in the context of a web application (it looks like you), you can automatically connect to HttpServletRequest or HttpServletResponse.
A request / response from the current request area will be entered.
@Component
public class SomeComponentInAWebApplicationContext {
@Autowired
private HttpServletRequest request;
@Autowired
private HttpServletResponse response;
...
}
+4
Rob beardow
source
to share