首页 > 代码库 > java_web总结(一)
java_web总结(一)
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;
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。