Implementing ServletResponseAware
might work in other situations, but it doesn't help with Freemarker and Struts2. :-( I just traced it through with a debugger, and found that...
by implementing ServletResponseAware
, I was given access to the response, and I could change the content-type from my action. Good.
once my action was done, control soon ended up in org.apache.struts2.views.freemarker.FreemarkerResult
, which renders the template
the method preTemplateProcess()
sets the response's content-type, ignoring the value I had set :-(
apparently there's a "custom attribute" that could be used to override this, but I haven't found any explanation in google yet
the FreemarkerResult
class itself can have a content-type set to override the default, but... not sure yet where that can be set from, maybe in a struts configuration?
So so far it doesn't seem that the action can set the content-type, but fortunately as Thomas notes above, this overrides all that:
${response.setContentType("text/xml")}
So at least it's possible from the templates. Sure would be easier and safer to give a set of xml-producing actions a common superclass that takes care of this...