I know this question is very similar to this one, but I feel its different and specific enough to warrant its own question here.
I've just inherited a Java web app project from a sole developer who left no documentation behind. Its a Spring MVC app with a basic package structure as follows:
com.ourOrg.app.controllers
ImageController
ProgramController
UserController
com.ourOrg.app.otherPackages
Each Controller
class is just a POJO annotated with @Controller
and @RequestMapping("/blah")
. For instance:
@Controller
@RequestMapping("/images")
public class ImageController() {
@RequestMapping(value="/saveImage", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<String> saveImage(@RequestParam(value="imageData", required=true) String imageXML, HttpServletRequest request){
// This method gets executed whenever the:
// http://ourSite.com/images/saveImage
// URL is hit
}
}
I have been asked to add the following HTTP headers to the Spring config so that we disable browser caching:
Pragma: no-cache
Cache-Control: no-cache
Expires: -1
The article I linked to above makes it sound like our controllers should be extending this WebContentGenerator
class. Unfortunately, there are dozens of controllers with an enormous number of methods, so refactoring each one to extend or inherit some base type is not really a viable option (unless its the only option!).
I've also seen articles that make it sound like you have to configure Spring to use AOP interceptors that modify your response headers, but now I'm really getting into unfamiliar territory.
Given our setup and implementation of Spring MVC, whats the easiest way for me to add these three simple headers to every response sent back by the server (regardless of which controller or method is executed)?
Thanks in advance!
Hoping you are using Spring 3, you can look at an interceptor, then you won't have to modify all of your controllers (since you said you had many). It looks like they may already have one implemented that you can just use. Check out Bozho's answer to this question how to set header no cache in spring mvc 3 by annotation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With