class="java" name="code">String code="gb2312"; HttpServletResponse response=ServletActionContext.getResponse(); //从数据库获取附件 Attach attach=attachService.findbyid(id); InputStream in=new FileInputStream(attach.getFilepath()); response.setContentType(attach.getFiletype()+";charset="+code); response.setHeader("Content-Disposition","attachment;filename="+new String(attach.getFilename().getBytes("gbk"),"iso-8859-1")); ServletOutputStream servletOutputStream=response.getOutputStream(); byte[] b = new byte[2048]; int k = 0; while ((k = in.read(b)) != -1) { servletOutputStream.write(b,0,k); } in.close();