Public String Exceldomnload () throws exception{try{/*string Path = Globalkeys.getfunctionconfig ("User_attach_save", "/ opt/tmp/"); Reguser ru = ((reguserlogininfo) request.getsession (). getattribute (Globalkeys.reg_user_in_session_name)). Getreguser (); String Tmppath = file.separator + "Import" + file.separator+ Ru.getname () + file.separator; File TargetFolder = new file (path, tmppath);//merge two paths via string fName = Request.getparameter ("FName"); */ Response.setcontenttype ("application/msexcel;"); Response.setheader ("Content-disposition", New String ("attachment;filename=" + "Error.xls"). GetBytes ("GB2312"), " UTF-8 ")); File F = new file ("D:/20121211165820140_err.xls");//file f = new file (Targetfolder.getpath () +file.separator+fname); FileInputStream in = new FileInputStream (f); byte b[] = new Byte[1024];int i = 0; Servletoutputstream out = Response.getoutputstream (), while ((I=in.read (b))!=-1) {out.write (b, 0, i);} Out.flush (); Out.close (); In.close ();} catch (Exception e) {e.printstacktrace ();} return null;}
Java Direct output Excel page implementation download