JSP动态输出Excel及中文乱码的解决(2)

 Object page = this;
 javax.servlet.jsp.JspWriter out;
 javax.servlet.jsp.PageContext pageContext =
  javax.servlet.jsp.JspFactory.getDefaultFactory().getPageContext(this, request, response, null, true, 8192, true);

 out = pageContext.getOut();
 JspWriter _originalOut = out;

 javax.servlet.http.HttpSession session = request.getSession(true);

 try { // error page try block
  out.print("\r\n");
  //[ /test_excel.jsp; Line: 2]
  response.reset(); //[ /test_excel.jsp; Line: 3]
  response.setContentType("application/vnd.ms-excel"); //[ /test_excel.jsp; Line: 4]
  Test.writeExcel(response.getOutputStream()); //[ /test_excel.jsp; Line: 5]
 } catch (Throwable __ee) {
  while (out != null && out != _originalOut) out = pageContext.popBody();
  ((weblogic.servlet.jsp.PageContextImpl)pageContext).handlePageException((Throwable)__ee);
 }

  //before final close brace...
}

  大家可以看到在response.reset();之后,Test.writeExcel(response.getOutputStream());之前正确的设置了response的输出内容。所以输出就正常了。

  最后,希望这篇文章能对你有所启发,如有错误之处,敬请批评指正!

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzxdyy.html