`
sumongh
  • 浏览: 222984 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

在liferay portal 上开发文件下载功能(转)

阅读更多
原来已经做好的一个portlet,使用的是jsp实现的,后来需要增加文件下载的功能,以下是解决办法:
  1. 开发一个portlet继承com.liferay.portlet.JSPPortlet;
  2. 覆盖processAction方法,如下:
  3. java 代码
    1. public class DownloadFile extends JSPPortlet {   
    2.             public void processAction(ActionRequest req,ActionResponse res){   
    3.                    File file = new File("your file ");   
    4.                    InputStream is = new FileInputStream(file);   
    5.                    com.liferay.util.servlet.ServletResponseUtil.sendFile(((ActionResponseImpl)res).getHttpServletResponse(), file.getName(), is);    
    6.             }   
    7.       }   

3. 修改portlet-ext.xml文件如下:

xml 代码
  1. <portlet>  
  2.   <portlet-name>100portlet-name>  
  3.   <display-name>downloaddisplay-name>  
  4.   <portlet-class>cn.javaedu.portlet.DownloadFileportlet-class>  
  5.   <init-param>  
  6.    <name>view-jspname>  
  7.    <value>/portlet/ext/test/view.jspvalue>  
  8.   init-param>  
  9.   <expiration-cache>300expiration-cache>  
  10.   <supports>  
  11.    <mime-type>text/htmlmime-type>  
  12.   supports>  
  13.   <resource-bundle>com.liferay.portlet.StrutsResourceBundleresource-bundle>  
  14.   <security-role-ref>  
  15.    <role-name>power-userrole-name>  
  16.   security-role-ref>  
  17.   <security-role-ref>  
  18.    <role-name>userrole-name>  
  19.   security-role-ref>  
  20.  portlet>  
 4. 在需要下载的页面上的链接如下写:
<*   href='<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">               </portlet:actionURL>' >download</a>
当用户点击download的下载链接时,系统就会提示用户保存文件
评论
1 楼 byones 2007-07-27  
不懂,liferay本身的CMS就带有文档下载的功能,干嘛要自己开发呢?

相关推荐

Global site tag (gtag.js) - Google Analytics