发布网友 发布时间:2024-10-24 13:08
共1个回答
热心网友 时间:2024-10-24 18:04
开发一个portlet继承com.liferay.portlet.JSPPortlet; 覆盖processAction方法,如下: java 代码 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); } } 3. 修改portlet-ext.xml文件如下: xml 代码 <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> 4. 在需要下载的页面上的链接如下写: <* href='<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>"> </portlet:actionURL>' >download</a> 当用户点击download的下载链接时,系统就会提示用户保存文件