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

文件的下传,上载

2012-12-27 
文件的上传,下载下载public ActionForward downkey(ActionMapping mapping,ActionForm form, HttpServletR

文件的上传,下载
下载

public ActionForward downkey(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) {String path=request.getSession().getServletContext().getRealPath("/")+ "key/";String filepath = request.getParameter("path");response.setContentType("application/octet-stream");response.addHeader("Content-Disposition","attachment;filename="+filepath);try {if (!"".equals(filepath)) {FileInputStream fis = new FileInputStream(path+filepath);ServletOutputStream sos = response.getOutputStream();int i = 0;while ((i = fis.read()) != -1) {sos.write(i);}fis.close();sos.close();}} catch (Exception e) {e.printStackTrace();logger.error("报表下载发生异常:" + e.toString());}return null;}

热点排行