form表单提交方式

form表单提交方式

如果通过form表单提交请求服务端去下载文件,这时当前页面不会发生跳转,服务端返回void,通过response 去写文件数据,页面会显示下载文件。

@RequestMapping(value = "/url")

public void exportFile(HttpServletRequest req, HttpServletResponse response, String rptId)

throws Exception {

OutputStream out = null;

try {

String rptName = "file";

String fileName = new String((rptName + excelAble.getFileSuffix()).getBytes("GBK"),

"8859_1");

response.reset();

response.setContentType("application/octec-stream");

response.setHeader("Content-disposition", "attachment; filename=" + fileName);

out = response.getOutputStream();

excelAble.exportFile(out);

} catch (Exception e) {

logger.error(e);

} finally {

if (out != null) {

out.close();

}

}

}

相关推荐

膨的解释
365app官方版下载

膨的解释

📅 09-14 👁️ 9805
如何移除 PDF 密碼
365app官方版下载

如何移除 PDF 密碼

📅 09-01 👁️ 5974
鬃字笔画写法
365app官方版下载

鬃字笔画写法

📅 01-26 👁️ 5879