标签:style blog http color java os io 文件
1、struts1ajax返回值
public ActionForward preChangeAccountPwd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 向页面返回添加帐号结果 response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); PrintWriter pw = response.getWriter(); pw.write(result); pw.close(); return null; }
2、excle
response.setHeader("Content-disposition","attachment;filename=temp.xls"); response.setContentType("application/octet-stream"); ServletOutputStream os = response.getOutputStream(); NetWorkForm uf = (NetWorkForm)form; FormFile ff = uf.getNetFile(); InputStream in = ff.getInputStream(); HSSFWorkbook wb = new HSSFWorkbook(in); HSSFSheet sheet = wb.getSheetAt(0); int rowNum = sheet.getLastRowNum(); × × workbook.write(os); os.close(); in.close(); return null; ======================== OutputStream os = response.getOutputStream(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment; filename="+ fileName+ ".xls"); // 第一步,创建一个webbook,对应一个Excel文件 HSSFWorkbook wb = new HSSFWorkbook(); × × wb.write(os); os.close(); response.setContentType("text/xml;charset=utf-8"); return null;
标签:style blog http color java os io 文件
原文地址:http://www.cnblogs.com/caroline4lc/p/3922673.html