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