1 package util; 2 3 import java.io.OutputStream; 4 import java.io.PrintWriter; 5 6 import javax.servlet.http.HttpServletResponse; 7 8 import org.apache.poi.ss.usermodel.Workbook; 9 10 public class ResponseUtil { 11 12 public static void write(HttpServletResponse response,Object o) throws Exception{ 13 response.setContentType("text/html;charset=utf-8"); 14 PrintWriter out = response.getWriter(); 15 out.println(o.toString()); 16 out.flush(); 17 out.close(); 18 } 19 20 public static void export(HttpServletResponse response,Workbook wb,String fileName)throws Exception{ 21 response.setHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("utf-8"),"iso8859-1")); 22 response.setContentType("application/ynd.ms-excel;charset=UTF-8"); 23 OutputStream out=response.getOutputStream(); 24 wb.write(out); 25 out.flush(); 26 out.close(); 27 } 28 }