日期:2014-05-18  浏览次数:20651 次

jsp中打开保存excel问题
我在jsp中做了一个excel导出的按纽,点机后回弹出一个对话框,可以直接打开,或者保存,保存没有问题,打开就回报找不到文件.
<%!
private   void   setResponse(HttpServletResponse   response,String   mime,String   name,String   ext){
response.setContentType(mime+ ";charset=gbk ");
if(name!=null){
StringBuffer   contentDisposition   =   new   StringBuffer( "\ "attachment;   filename=\ " "); contentDisposition.append(name).append(ext);
response.setHeader( "Content-disposition ",contentDisposition.toString());

}
}
%>

<%
setResponse(response, "text/plain ", "downkm2yyksqd ", ".xls ");
try   {
in=new   FileInputStream(fileName);
outPutStream=response.getOutputStream();
int   b;
while((b=in.read())!=-1){
outPutStream.write(b);
}
in.close();
outPutStream.flush();
}   catch   (FileNotFoundException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}   catch   (IOException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}

%>

------解决方案--------------------
應該是文件路徑問題,如果發布後是war文件,可以把war解壓為一文件夾發布試一下。
------解决方案--------------------
我刚好也要做导出EXCEL 请问导出的代码就这些吗?需要导入哪些JAR包
万分感激啊~1