Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ntln(“您的excel文件已生成!”); }catch(filenotfounde异常){ //TODO自动生成的捕捉块 e、 printStackTrace(); } } /** *@请参阅HttpServlet#doPost(HttpServletRequest请求,HttpServletResponse响应) */ 受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)引发ServletException、IOException{ System.out.println(“Hi from Do post”); getValues(); } }_Java_Jsp_Servlets - Fatal编程技术网

Java ntln(“您的excel文件已生成!”); }catch(filenotfounde异常){ //TODO自动生成的捕捉块 e、 printStackTrace(); } } /** *@请参阅HttpServlet#doPost(HttpServletRequest请求,HttpServletResponse响应) */ 受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)引发ServletException、IOException{ System.out.println(“Hi from Do post”); getValues(); } }

Java ntln(“您的excel文件已生成!”); }catch(filenotfounde异常){ //TODO自动生成的捕捉块 e、 printStackTrace(); } } /** *@请参阅HttpServlet#doPost(HttpServletRequest请求,HttpServletResponse响应) */ 受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)引发ServletException、IOException{ System.out.println(“Hi from Do post”); getValues(); } },java,jsp,servlets,Java,Jsp,Servlets,您可以写入servlet输出流,而不是通过FileOutputStream写入文件 OutputStream servletoutputstream = response.getOutputStream(); response.setContentType("application/msexcel"); response.addHeader("Content-Disposition", "filename=filename.xls"); .... workbook.write(servletou

您可以写入servlet输出流,而不是通过FileOutputStream写入文件

OutputStream servletoutputstream = response.getOutputStream();
response.setContentType("application/msexcel");
response.addHeader("Content-Disposition", "filename=filename.xls");
....
workbook.write(servletoutputstream);

但正如我在评论中所说,Excel是在Excel中打开还是在浏览器中打开取决于您无法控制的用户设置。

Excel是在Excel中打开还是在浏览器中打开(或者由于没有Excel而提示下载)是一种用户端设置,除非这是公司内部网,否则您无法为您的用户控制。为什么人们发布问题而不发布代码!!!请发布您的代码…@CPU100-请在post@tom谢谢你添加它。我会看一看,看看我是否能帮上忙谢谢你的建议,我会尝试相应地重构我的代码。在你的帮助下,我可以做我想做的事情,谢谢你的语气developerjk,你节省了我的时间。
OutputStream servletoutputstream = response.getOutputStream();
response.setContentType("application/msexcel");
response.addHeader("Content-Disposition", "filename=filename.xls");
....
workbook.write(servletoutputstream);