• 读取页面传的数据


      从流中读取传递的参数:

      

    //一个例子:
    @RequestMapping(value = "/exportSeller",method = {RequestMethod.POST,RequestMethod.GET})
    public String exportSeller(HttpServletRequest request, HttpServletResponse response) throws BusinessException, IOException {

    StringBuffer params = new StringBuffer();
    String line = null;
    try {
    BufferedReader reader = request.getReader();
    while((line = reader.readLine()) != null) {
    params.append(line);
    }
    }catch(Exception e) {
    System.out.println(e.toString());
    }

    Map<String,String> map = new HashMap<String,String>();
    String[] pa = params.toString().split("\&");
    for (String s:pa) {
    String[] strings = s.split("\=");
    if (strings.length > 1){
    map.put(strings[0],strings[1]);
    }else{
    map.put(strings[0],"");
    }
    }

    ExcelParam param = new ExcelParam();
    param.setCashCode(map.get("cashCode"));
    param.setApplyEndDate(map.get("applyEndDate"));
    param.setApplyStartDate(map.get("applyStartDate"));
    param.setAuditEndDate(map.get("auditEndDate"));
    param.setAuditStartDate(map.get("auditStartDate"));
    param.setCashDownAmt(map.get("cashDownAmt"));
    param.setCashUpAmt(map.get("cashUpAmt"));
    param.setExportStatus(map.get("exportStatus"));
    param.setUserName(map.get("userName"));

    // 获取workbook对象
    Workbook workbook = excelService.exportSheetBySeller(param);
    // 判断数据
    if(workbook == null) {
    return "fail";
    }
    // 设置excel的文件名称
    String excelName = "服务机构-帐务信息";
    // 重置响应对象
    response.reset();
    // 当前日期,用于导出文件名称
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    String dateStr = excelName+"-"+sdf.format(new Date())+".xls";
    // 指定下载的文件名--设置响应头
    response.setHeader("Content-Disposition", "attachment;Filename=" + URLEncoder.encode(dateStr, "UTF-8"));
    //response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(dateStr, "UTF-8")+".xls");
    response.setContentType("application/vnd.ms-excel;charset=UTF-8");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    // 写出数据输出流到页面
    try {
    OutputStream output = response.getOutputStream();
    BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
    workbook.write(bufferedOutPut);
    bufferedOutPut.flush();
    bufferedOutPut.close();
    output.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    return "success";
    }
  • 相关阅读:
    前端编译原理 简述-jison
    GraphQL入门
    前端理解控制反转ioc
    window.onload和JQuery中$(function(){})的区别即其实现原理
    移动web之一像素问题
    display:table和display:table-cell的妙用
    sticky footer布局
    Elements in iteration expect to have 'v-bind:key' directives错误的解决办法
    vue模拟后台数据,请求本地数据的配置(旧版本dev-server.js,新版本webpack.dev.conf.js)
    使用vue-cli脚手架搭建项目,保存编译时出现的代码检查错误(ESLint)
  • 原文地址:https://www.cnblogs.com/chengyangyang/p/9946846.html
Copyright © 2020-2023  润新知