所有示例均在gihub(ssh_base)中====>https://github.com/chengyangyang

读取页面传的数据

 

  从流中读取传递的参数:

  

//一个例子:
@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";
}

 

posted @ 2018-11-12 15:40  ☞书香门第☜  阅读(167)  评论(0编辑  收藏  举报
http://count.knowsky.com/count1/count.asp?id=434520&sx=1&ys=64"