Http应答返回文件

public ActionForward dz(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception
{
System.out.println("for duizhang");
String date=request.getParameter("date");
if(null!=date && date.length()==8){

String path=BinFile.fileRealPath;
FileInputStream fis = new FileInputStream(path);
String[] names=path.split("/");
path = names[names.length-1];
response.setCharacterEncoding("UTF-8");
response.addHeader("Content-Disposition","attachment;filename=\""+ java.net.URLEncoder.encode(path,"UTF-8") + "\"");
OutputStream out = response.getOutputStream();
byte[] buff = new byte[1024];
int readed = -1;
while((readed = fis.read(buff)) > 0)
  out.write(buff, 0, readed);
out.flush();
out.close();
}
return  mapping.findForward("dz");
  }

你可能感兴趣的:(.net)