struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Burton Rhodes <>
Subject Unable to change content-type with Interceptor?
Date Sun, 30 Dec 2012 17:18:52 GMT
I'm not sure what I'm doing wrong, but I cannot for the life of me change
the content-type of the response using an interceptor.  My interceptor code
is below.  The example below seems a bit absurd, but eventually I will add
code to change the content-type dynamically from "application/json" to
"text/plain" depending on what the request will "accept" (this is to fix an
IE bug related to ajax file uploads).  What am I missing here?  Many thanks
in advance.

<!-- struts.xml snippit -->
<package name="jsonSecure" namespace="/app/json" extends="json-default">

        <interceptor name="jsonDynamicContentType"
        <interceptor-stack name="dynamicContentType">
            <interceptor-ref name="json"/>
            <interceptor-ref name="jsonDynamicContentType"/>

    <action name="TeamFileJson_upload"
class="com.afs.web.action.json.TeamFileJsonAction" method="upload">
        <interceptor-ref name="dynamicContentType"/>
        <result type="json"/>

<!-- Custom Interceptor -->
public class JsonDynamicContentTypeInterceptor  extends AbstractInterceptor

    public String intercept(ActionInvocation invocation) throws Exception {

        // Go down the chain first
        String result = invocation.invoke();

        // Change the content-type of the response
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = (HttpServletResponse)

        // This doesn't work either

        // Continue the chain
        return result;



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message