Spring MVC - 无法调用getWriter(),getOutputStream()已调用

时间:2017-11-02 13:25:04

标签: java spring-mvc jasper-reports thymeleaf

可以很好地查看Pdf文件,在控制台中抛出异常。

我研究过,大多数问题都是通过将方法声明为void或返回null来解决的;尝试过相同但错误仍然被抛出。

感谢任何帮助,谢谢!

控制器方法

@RequestMapping(value = "/repRange/view/pdf", method = RequestMethod.GET)/
public void viewRepRangeAsPdf(
        SaleReportRepOption options
        ) throws Exception{
    prepRepRange(options);
    saleReport.generateReport();
}

prepRepRange只是设置某些变量

private void prepRepRange(SaleReportRepOption options){
    saleReport.setJasperFilename("rpt_SaleRepRange.jasper");
    saleReport.setOutputFilename("saleRepRange.pdf");
    List<SaleReportRepInfo> saleReportRepInfo = saleReportRepInfoService.findAllByOption(options);
    saleReport.setContent(saleReportRepInfo);       
}

最后报告在这里生成

public void generateReport() throws IllegalArgumentException, JRException, NamingException, SQLException, IOException {
    JasperReport jasperReport = getJasperReport(jasperFilename);
    JRDataSource jrDataSource = new JRBeanCollectionDataSource(this.content);
    byte[] bytes = null;
    bytes = JasperRunManager.runReportToPdf(jasperReport, parameters, jrDataSource);

    resp.reset();
    resp.resetBuffer();
    resp.setContentType("application/pdf");
    resp.setContentLength(bytes.length);
    String headerValue = headerValue = "inline; filename=" + outputFilename;
    resp.setHeader("Content-Disposition", headerValue);
    ServletOutputStream ouputStream = resp.getOutputStream();
    ouputStream.write(bytes, 0, bytes.length);
    ouputStream.flush();
    ouputStream.close();
}

所有方法都成功完成而不会抛出错误。完成控制器viewRepRangeAsPdf()之后,在核心文件中的某个地方抛出错误。

我不会写或输出任何内容,所有方法也会返回无效。

堆栈跟踪

  

错误[io.undertow.request](默认任务-23)UT005023:异常   处理/ aiwaweb / saleReport / repRange / view / pdf的请求:   org.springframework.web.util.NestedServletException:Request   处理失败;嵌套异常是   java.lang.IllegalStateException:UT010006:无法调用getWriter(),   已经调用了getOutputStream()   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)     在   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:687)at   org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)at   io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)     在   io.undertow.servlet.handlers.FilterHandler $ FilterChainImpl.doFilter(FilterHandler.java:129)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:317)     在   org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)     在   org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:100)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)     在   org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)     在   org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)     在   org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)     在   org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)     在   io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)     在   io.undertow.servlet.handlers.FilterHandler $ FilterChainImpl.doFilter(FilterHandler.java:131)     在   io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)     在   io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)     在   io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)     在   org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)     在   io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)     在   io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)     在   io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)     在   io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)     在   io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)     在   io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)     在   io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)     在   io.undertow.servlet.handlers.ServletInitialHandler.access $ 000(ServletInitialHandler.java:81)     在   io.undertow.servlet.handlers.ServletInitialHandler $ 1.handleRequest(ServletInitialHandler.java:174)     在   io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)     在   io.undertow.server.HttpServerExchange $ 1.run(HttpServerExchange.java:793)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)引起:   java.lang.IllegalStateException:UT010006:无法调用getWriter(),   已经调用了getOutputStream()   io.undertow.servlet.spec.HttpServletResponseImpl.getWriter(HttpServletResponseImpl.java:353)     在   javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:152)     在   javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:152)     在   org.springframework.security.web.util.OnCommittedResponseWrapper.getWriter(OnCommittedResponseWrapper.java:149)     在   org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335)     在   org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:189)     在   org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)     在   org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)     在   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)     在   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)     在   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)     ... 66更多

我使用Spring Mvc 4.3.3.RELEASE,Thymeleaf 3.0.1.RELEASE,Jasper 6.4.3

0 个答案:

没有答案