zoukankan      html  css  js  c++  java
  • 读取页面传的数据

      从流中读取传递的参数:

      

    //一个例子:
    @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";
    }
  • 相关阅读:
    BGP的MA网络、自动汇总、聚合
    [转载]CISCO配置HSRP
    BGP选路十种方法总结 用实验详细介绍(副实验拓扑)
    [win技巧] windows 7的上帝模式你用过吗?【相信你没用过!如此方便的的设置】
    CISCO BGP(EBGP/IBGP)基本配置小结以及如何防止BGP路由黑洞(附实验拓扑)
    执行外部程序
    C#编写COM组件
    在SQL Server 2005上遇到了先删除已运行维护计划后,再删除代理中由其产生的作业时,提示删除失败,如何处理?
    关于存储过程编写的一点总结(转)
    WCF:调用方未由服务器进行身份验证
  • 原文地址:https://www.cnblogs.com/chengyangyang/p/9946846.html
Copyright © 2011-2022 走看看