html表单数据提交方法,6种form表单提交方式-很全了_AnyReport

html表单数据提交方法,6种form表单提交方式-很全了_AnyReport如果通过 form 表单提交请求服务端去下载文件 这时当前页面不会发生跳转 服务端返回 void 通过 response 去写文件数据 页面会显示下载文件 RequestMappi value url publicvoidex HttpServletR HttpServletR StringrptId throw

如果通过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();

}

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/226314.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月16日 下午11:50
下一篇 2026年3月16日 下午11:50


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号