Reponse响应头设置备注

简单记录一下java的reponse头设置类型

content-type

常见的媒体格式类型如下:
- text/html : HTML格式
- text/plain :纯文本格式
- text/xml : XML格式
- image/gif :gif图片格式
- image/jpeg :jpg图片格式
- image/png:png图片格式

以application开头的媒体格式类型:
- application/xhtml+xml :XHTML格式
- application/xml : XML数据格式
- application/atom+xml :Atom XML聚合格式
- application/json : JSON数据格式
- application/pdf :pdf格式
- application/msword : Word文档格式
- application/octet-stream : 二进制流数据(如常见的文件下载)
- application/x-www-form-urlencoded : 中默认的encType,form表单数据被编码为key/value格式发送到服务器(表单默认的提交数据的格式)
另外一种常见的媒体格式是上传文件之时使用的:
- multipart/form-data : 需要在表单中进行文件上传时,就需要使用该格式
以上就是我们在日常的开发中,经常会用到的若干content-type的内容格式。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
@RequestMapping("/exportExcel") public void exportExcel(HttpServletResponse response) throws IOException { // 获取要导出的数据 List<Student> studentList = studentService.getAllStudent(); // 创建工作簿 @SuppressWarnings("resource") XSSFWorkbook workbook = new XSSFWorkbook(); // 创建工作表 XSSFSheet sheet = workbook.createSheet("学生信息表"); // 创建表 XSSFRow row = sheet.createRow(0); row.createCell(0).setCellValue("ID"); row.createCell(1).setCellValue("学号"); row.createCell(2).setCellValue("姓名"); row.createCell(3).setCellValue("性别"); row.createCell(4).setCellValue("出生日期"); row.createCell(5).setCellValue("地址"); row.createCell(6).setCellValue("电话"); row.createCell(7).setCellValue("照片"); row.createCell(8).setCellValue("备注"); row.createCell(9).setCellValue("所属宿舍"); // 填充数据 for (int i = 0; i < studentList.size(); i++) { row = sheet.createRow(i + 1); row.createCell(0).setCellValue(studentList.get(i).getStuId()); row.createCell(1).setCellValue(studentList.get(i).getStuNo()); row.createCell(2).setCellValue(studentList.get(i).getStuName()); row.createCell(3).setCellValue(studentList.get(i).getStuSex()); row.createCell(4).setCellValue(studentList.get(i).getStuBirth()); row.createCell(5).setCellValue(studentList.get(i).getStuAddress()); row.createCell(6).setCellValue(studentList.get(i).getStuPhone()); row.createCell(7).setCellValue(studentList.get(i).getStuPhoto()); row.createCell(8).setCellValue(studentList.get(i).getStuRemark()); row.createCell(9).setCellValue(studentList.get(i).getStuDormitory()); } // 设置响应信息 response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment;filename=student.xls"); // 输出Excel文件 workbook.write(response.getOutputStream()); }需要的依赖
最新发布
06-09

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值