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

liferay开发文件上载功能

2012-11-01 
liferay开发文件下载功能原来已经做好的一个portlet,使用的是jsp实现的,后来需要增加文件下载的功能,以下

liferay开发文件下载功能
原来已经做好的一个portlet,使用的是jsp实现的,后来需要增加文件下载的功能,以下是解决办法:

    开发一个portlet继承com.liferay.portlet.JSPPortlet; 覆盖processAction方法,如下: public class DownloadFile extends JSPPortlet { public void processAction(ActionRequest req,ActionResponse res){ File file = new File("your file "); InputStream is = new FileInputStream(file); com.liferay.util.servlet.ServletResponseUtil.sendFile(((ActionResponseImpl)res).getHttpServletResponse(), file.getName(), is); } } <portlet> <portlet-name>100portlet-name> <display-name>downloaddisplay-name> <portlet-class>cn.javaedu.portlet.DownloadFileportlet-class> <init-param> <name>view-jspname> <value>/portlet/ext/test/view.jspvalue> </init-param> <expiration-cache>300expiration-cache> <supports> <mime-type>text/htmlmime-type> </supports> <resource-bundle>com.liferay.portlet.StrutsResourceBundleresource-bundle> <security-role-ref> <role-name>power-userrole-name> </security-role-ref> <security-role-ref> <role-name>userrole-name> </security-role-ref> </portlet> <a href='<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>"> </portlet:actionURL>' >download</a>?当用户点击download的下载链接时,系统就会提示用户保存文件

热点排行