liferay portlet实现文件下载的方法案例:
String name=FilePath; name=name.substring(name.lastIndexOf("/")+1, name.length()); HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(resourceRequest); HttpServletResponse httpResponse = PortalUtil.getHttpServletResponse(resourceResponse); httpResponse.setContentType("applicationoctet-stream;charset=UTF-8"); String userAgent = httpRequest.getHeader("User-Agent").toLowerCase(); byte[] bytes = userAgent.contains("safari") ? name.getBytes("UTF-8") : name.getBytes("gbk"); name = new String(bytes, "ISO-8859-1"); httpResponse.setHeader("Content-disposition", String.format("attachment;filename=\"%s\"", name)); OutputStream out=resourceResponse.getPortletOutputStream(); //repository.getFile("", SVNRevision.HEAD.getNumber(), null, out); //把文件流放入out中,此处省略 if(out!=null){ out.flush(); out.close(); }