首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

到response.reset()哪里就过不去了,麻烦啊!

2011-12-21 
到response.reset()哪里就过不去了,麻烦高手进啊!!!!!急!if(request.getParameter(outxls)!null){Syste

到response.reset()哪里就过不去了,麻烦高手进啊!!!!!急!
if(request.getParameter("outxls")!=null){ 
System.out.println("outxls!=null"); 
String filepath=SaveToExcel.SaveToExcelFile(SelectSql,WhereParameter,"线路营收",DateString,SumColumnNames); 
if(filepath.equals("")){ 
out.print("<script>alert('导出程序出现问题,请联系管理员!');</script>"); 
}else{ 
DownFileStream.SendDownFile(response,filepath,"线路营收列表.xls"); 
out.clear(); 
out = pageContext.pushBody(); 

return; 



----------------------------------------------------------------- 
package Common; 

import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.OutputStream; 
import java.net.URLEncoder; 
import javax.servlet.http.HttpServletResponse; 
import javax.servlet.jsp.JspWriter; 
import javax.servlet.jsp.PageContext; 

public class DownFileStream { 

public static void SendDownFile(HttpServletResponse response,String filepath,String filename) throws IOException{ 
response.reset();//为什么到这里就过不去了那? response.setContentType("application/x-download"); 
String filedisplay =filename; 
filedisplay = URLEncoder.encode(filedisplay,"UTF-8"); 
response.addHeader("Content-Disposition","attachment;filename=" + filedisplay); 
OutputStream outp = null; 
FileInputStream in = null; 
try { 
outp = response.getOutputStream(); 
in = new FileInputStream(filepath); 
  byte[] b = new byte[1024]; 
int i = 0; 
while((i = in.read(b)) > 0){ 
outp.write(b, 0, i); 

outp.flush(); 


catch(Exception e){ 
System.out.println("Error!"); 
e.printStackTrace(); 

finally{ 
if(in != null){ 
in.close(); 
in = null; 

if(outp != null){ 
outp.close(); 
outp = null; 






到response.reset()哪里就过不去了。。出现NULL错误。。。 
请问是什么原因那? 


[解决办法]
如果是正常的,参考一下http://blog.csdn.net/patriotlml/archive/2007/05/28/1628556.aspx!
如果解决了,别忘了给分哦!没解决就算了!呵呵

热点排行