我想将JSP页中用 SQL select *From ...出来的数据倒出成excel文件,点击直接弹出对话框提示下载,用一下回贴的方法会报 bis  =  new  BufferedInputStream(new  FileInputStream(getServletContext().getRealPath(""  +  filename)));  
此行有错,到底是怎么回事?————————————————————————
——————————————————————
这是简单的JSP,你可以改造成SERVLET,使用方法,例如此文件名是getfile.jsp  
与此文件的同目录下有一个test.doc的word目录,则用  
http://localhost/getfile.jsp?file=test.doc  
<%@page  import="java.util.*"%>  
<%@page  import="java.io.*"%>  
<%@page  import="java.net.*"%>  
<%  
       String  filename  =  "";  
       if  (request.getParameter("file")  !=  null)  {  
               filename  =          request.getParameter("file");  
       }  
       response.setContentType("application/msword");  
       response.setHeader("Content-disposition","attachment;  filename="+filename);  
         
       BufferedInputStream  bis  =  null;  
       BufferedOutputStream  bos  =  null;  
       try  {  
               bis  =  new  BufferedInputStream(new  FileInputStream(getServletContext().getRealPath(""  +  filename)));  
               bos  =  new  BufferedOutputStream(response.getOutputStream());  
 
               byte[]  buff  =  new  byte[2048];  
               int  bytesRead;  
 
               while(-1  !=  (bytesRead  =  bis.read(buff,  0,  buff.length)))  {  
                       bos.write(buff,0,bytesRead);  
               }  
 
       }  catch(final  IOException  e)  {  
               System.out.println  (  "&sup3;&ouml;&Iuml;&Ouml;IOException."  +  e  );  
       }  finally  {  
               if  (bis  !=  null)  
                       bis.close();  
               if  (bos  !=  null)  
                       bos.close();  
       }  
       //return;  
%>
-------------------------------------------
----------------------------------------
另外我又用了下面的方法也不行,报int  status  =  khViewBean.getStatus();  错啊,到底怎么搞?
请高手指教。---------------------------------------------------首先你的页面上要有一个按钮:save  
这个按钮先做查询数据库,然后action转到保存excell的页面,即我给你的这些代码,由于我的是用这个页面是隐藏的,点击save时有跳出界面问你是打开还是保存,xxxxxxxxxxxxxx是你调用数据库的记录,  
<%@  page  contentType="text/html;charset=gb2312"  %>    
<%@  page  import="java.lang.*"%>  
<%  
           try{                                    
               response.setContentType("Application/msexcel");  
       response.setHeader("Content-Disposition",  "attachment;filename=trainlist.xls");                            
                       StringBuffer  cont=new  StringBuffer("");  
%>  
<HTML>  
<HEAD>  
<META  http-equiv="Content-Style-Type"  content="text/css">      
</HEAD>  
<BODY>  
<br><br><br>  
<%  
           int  status  =  khViewBean.getStatus();  
           if  (status  ==  0){  
                       int  rscount  =  khViewBean.getRSCount();  
%>  
<%  
           cont.append("<html><head><META  content=\'text/html;  charset=gb2312\'  http-equiv=Content-Type></head><body>\r\n");  
           cont.append("<h1>&nbsp;SOP&Icirc;&Auml;&micro;&micro;&sup2;é&Ntilde;&macr;&frac12;á&sup1;&ucirc;</h1>");  
           cont.append("<table  width='100%'  border='1'>\r\n");              
           cont.append("<tr>\r\n");              
           cont.append("<td  height='19'>&Icirc;&Auml;&frac14;&thorn;&ordm;&Aring;&nbsp;</td>\r\n");  
           cont.append("<td  height='19'>&Icirc;&Auml;&frac14;&thorn;&Atilde;&ucirc;&nbsp;</td>\r\n");  
           cont.append("<td  height='19'>&sup2;&iquest;&Atilde;&Aring;&nbsp;</td>\r\n");  
           cont.append("<td  height='19'>&Eacute;ú&ETH;§&Ecirc;±&frac14;&auml;&nbsp;</td>\r\n");  
           cont.append("</tr>\r\n");              
           cont.append("<tr>\r\n");  
                       cont.append("<td>"+xxxxxxxxxxxxxxxxxxxxxxxx  +"&nbsp;</td>\r\n");  
                       cont.append("<td>"+xxxxxxxxxxxxxxxxxxxxxxxx  +"&nbsp;</td>\r\n");  
                       cont.append("<td>"+xxxxxxxxxxxxxxxxxxxxxxxx  +"&nbsp;</td>\r\n");  
                       cont.append("<td>"+xxxxxxxxxxxxxxxxxxxxxxxx  +"&nbsp;</td>\r\n");  
           cont.append("</tr>\r\n");              
                                   cont.append("<tr>\r\n");  
                                   cont.append("<td>"+xxxxxxxxxxxxxxxxxxxxxxxx  +"&nbsp;</td>\r\n");  
                                   cont.append("<td>"+xxxxxxxxxxxxxxxxxxxxxxxx  +"&nbsp;</td>\r\n");  
                                   cont.append("<td>"+xxxxxxxxxxxxxxxxxxxxxxxx  +"&nbsp;</td>\r\n");  
                                   cont.append("<td>"+xxxxxxxxxxxxxxxxxxxxxxxx  +"&nbsp;</td>\r\n");  
           }  
           cont.append("</table>\r\n");              
           cont.append("</body></html>\r\n");  
           response.getWriter().println(cont.toString());  
           response.getWriter().close();  
%>  
<%    
           }  
           else  if  (status  >  0)  {  
%>  
           <hr  color="#6699CC">  
           <span  class="text"><font  color="blue"  size="16"><center><P>&Icirc;&THORN;&Ecirc;&yacute;&frac34;&Yacute;&nbsp;</P></center></font></span>  
<%  
           }  
           else  if  (status  <  0)  {  
%>  
           <hr  color="#6699CC">  
           <span  class="text"><font  color="red"  size="16"><center><P>·&cent;&Eacute;ú&acute;í&Icirc;ó&nbsp;</P></center></font></span>  
<%  
           }  
%>    
<hr  color="#6699CC">  
<%  
           }  
           catch  (Exception  e){  
                       out.println(e.toString());  
           }  
%>  
</BODY>  
</HTML>