Determine Path to Portlet Assets in Liferay JSP Files

When developing the front end (i.e. templates and JSP files) for portlets you will definitely at some want to include/reference custom assets, such as images. Luckily, in Liferay in order to determine the path to your portlet’s assets you only need to follow two steps. In your view.jsp (or any custom JSP file for that matter):

  1. specify correct portlet taglib (Liferay 6+)
    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
    
  2. and to reference portlet assets use request.getContextPath(), e.g.
    <img src="<%=request.getContextPath()%>/img/filter.png" />
    
  3. That’s it. This works for all assets deployed inside your portlet.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *