url=append+'/report/download2.do?name='+name传到后台name为空。
js
$("#btn_his_download").on("click", function () {
var name = $("#lines").find("option:selected").text();
var $form = $('<form method="GET"></form>');
$form.attr('action', appName + '/report/download2.do?name='+name);
$form.appendTo($('body'));
$form.submit();
});
controller
@RequestMapping("/download2.do")
public void download2(HttpServletRequest request, HttpServletResponse response) throws IOException {
String name = request.getParameter("name");
System.out.println(name);
String fileName = request.getSession().getServletContext().getRealPath("tcc/reports/upload/")+name;
InputStream bis = new BufferedInputStream(new FileInputStream(new File(fileName)));
name = URLEncoder.encode(name,"UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=" + name);
response.setContentType("multipart/form-data");
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
int len = 0;
while((len = bis.read()) != -1){
out.write(len);
out.flush();
}
out.close();
}