Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to download file in liferay 6.2 ?

    • 0
    • 2
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 4.97k
    Comment on it

    Hello Guy's
    Below code will help you to download file from server using liferay 6.2.
    Here I am writing a portlet to download file.
    For better understanding create portlet in your eclipse and follow below steps :
    Step: 1
    Edit view.jsp and put below code

    <%@ taglib uri="" prefix="portlet"%>
    <%@ taglib prefix="liferay-portlet" uri="" %>
     <portlet:defineObjects />
     <a href="<portlet:resourceURL/>">Download</a>

    When you click on "Download" link, It's call to serveResource(ResourceRequest request, ResourceResponse response) which is defined in below class.

    Step: 2
    Create and put below code:

    package com.bhagwan;
    import javax.portlet.ResourceRequest;
    import javax.portlet.ResourceResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import com.liferay.portal.kernel.servlet.ServletResponseUtil;
    import com.liferay.portal.util.PortalUtil;
    import javax.portlet.PortletException;
    import com.liferay.util.bridges.mvc.MVCPortlet;
    public class DownloadFile extends MVCPortlet
        public void serveResource(ResourceRequest request, ResourceResponse response)
                throws IOException, PortletException {
            try {
                File file = new File("/casefile.xlsx");
                InputStream in = new FileInputStream(file);
                HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(response);
                HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(request);
                ServletResponseUtil.sendFile(httpReq,httpRes, file.getName(), in, "application/download");
            } catch (Exception e) {

    You have any quires, Please comment on blog.
    Thank you

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: