jonmor
Mar 17th, 2006, 02:39 PM
I want to explicitly set the content type of some responses to 'text/xml' (away from the default 'text/html'). I've looked back through the archives for how to do this and the recurrent answer is to set the content type for the View. Trouble is, I really can't see how I would do this. Taking a very simplified example, where I'm simply wanting to take the output of a JSP page and set the content type for it, I might have this in my AbstractController subclass:
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse res) throws Exception {
return new ModelAndView("xmlPage");
}
How do I set the content type for the view here? If I do a getView on the ModelAndView, I will get a null, because the view hasn't been resolved yet. (And even if I did, I would need to cast it from View to something like AbstractView, which contains the setContentType method). I don't want to set this globally in my ViewResolver, as some responses should be text/xml and others text/html.
Any pointers would be appreciated.
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse res) throws Exception {
return new ModelAndView("xmlPage");
}
How do I set the content type for the view here? If I do a getView on the ModelAndView, I will get a null, because the view hasn't been resolved yet. (And even if I did, I would need to cast it from View to something like AbstractView, which contains the setContentType method). I don't want to set this globally in my ViewResolver, as some responses should be text/xml and others text/html.
Any pointers would be appreciated.