2012-12-30 48 views
0

我有一個應用程序與Spring MVC 3.1.3和用Dojo 1.4開發的用戶界面。該應用程序有幾個控制器處理通過dojo.io.iframe.send上傳的二進制文件。該控制器將具有與Spring MVC:如何修改spring controller發送的響應?

<html><body><textarea>{my json response}</textarea></body></html>. 

我實現了在web.xml中定義自定義過濾器包圍的JSON響應:

<filter> 
    <filter-name>dojoIframeFilter</filter-name> 
    <filter-class>com.app.web.MultipartAjaxFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>dojoIframeFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

過濾器的doFilter有此問題,從http://www.oracle.com/technetwork/java/filters-137243.html

public void doFilter(ServletRequest request, ServletResponse response, 
     FilterChain chain) throws IOException, ServletException { 

    if (request.getContentType() != null 
      && request.getContentType().contains("multipart/form-data")) { 
     CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse) response); 

     chain.doFilter(request, wrapper); 
     log.info(wrapper.toString()); 
     //Modify response here 
    } 
    else { 
     chain.doFilter(request, response); 
    } 
} 

包裝的輸出是空的。我還嘗試了許多其他組合,例如爲Spring的調度程序servlet放置自定義過濾器,取消doFilter中的if塊,這些都不起作用。我也試過編寫一個也失敗的Spring攔截器。任何人都可以提出任何其他想法嗎?

在此先感謝。

更新:我禁用彈簧安全和測試與純彈簧mvc但問題依然存在。我修改了標題和問題描述。

+0

你可以給你正在使用的CharResponseWrapper的完全合格的類名嗎? –

+0

@TomMcIntyre您是否建議將FQCN添加到類型聲明中,還是您要求?無論如何,它是com.app.web.CharResponseWrapper –

回答