Liferay DXP Free Tier    |    From download to running in minutes    |    Get started →

Blogs

An alternative to request.getContextPath(),if not working in liferay DXP

Manushi Jani
Manushi Jani
Alle Minuutin Luku

Hello Folks,

In order to to achieve the context path(relative path of a liferay portlet) we have been using a method called public String getContextPath().

Ex. we want to include an image , css or js file in a jsp .We write something as following:

<script src="<%=request.getContextPath()%>/js/mobileCompatibility.js"></script>

<script src="<%=request.getContextPath()%>/css/main.css"></script>

We are not able to achieve this sometimes, the issue is still unknown since this works for some version of Liferay 7.2 fix packs while not in the latest ones.

So the alternate solution which can be used as a fix is :

<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>

<c:set var="ctx" value="${pageContext.request.contextPath}" /> 
<link rel="stylesheet" type="text/css" href="${ctx}/css/main.css" />

Sivun kommentit

Related Assets...

Tuloksia Ei Löytynyt

More Blog Entries...

Ben Turner
marraskuuta 26, 2026
Himanshu Chauhan
marraskuuta 20, 2026
Tony Lim
marraskuuta 19, 2026