到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!
如果解决了,别忘了给分哦!没解决就算了!呵呵