Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Including jsp fragment into jsp page Liferay 7
I've tried two different approaches:
1.
2.
The view.jsp and priceOffer.jsp both reside in /resources.
But none of them gave me the expected result.
For 1. didn't get any errors, nor anything at all,
For 2. it gave me FileNotFound exception, and pointed to a non-existent place.
I need a short, working snippet. Thank you!
1.
<liferay-util:include page="priceOffer.jsp" servletContext="<%=this.getServletContext() %>">
<liferay-util:param name="name" value="${pricy.userName }" />
<liferay-util:param name="price" value="${pricy.price }" />
<liferay-util:param name="currency" value="USD" />
</liferay-util:include>
2.
<jsp:include page="priceOffer.jsp">
<jsp:param name="name" value="${pricy.userName }" />
<jsp:param name="price" value="${pricy.price }" />
<jsp:param name="currency" value="USD" />
</jsp:include>
The view.jsp and priceOffer.jsp both reside in /resources.
But none of them gave me the expected result.
For 1. didn't get any errors, nor anything at all,
For 2. it gave me FileNotFound exception, and pointed to a non-existent place.
I need a short, working snippet. Thank you!
Enrique Valdes Lacasa, modified 5 Years ago.
Junior Member
Posts: 92
Join Date: 7/29/14
Recent Posts
I use this and it works on Liferay 7.2.
In your init.jsp add:
And after that just use:
Then, in the included JSP, to get the parameter:
It won't work without specifying the serviceContext with the application object.
According to : https://portal.liferay.dev/docs/7-1/tutorials/-/knowledge_base/t/using-liferay-util-include:
The servletContext refers to the request context that the included JSP should use. Passing <%= application %> to this attribute lets the included JSP use the same request object as other objects that might be set in the prior JSP.
Kind regards.
In your init.jsp add:
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
And after that just use:
<liferay-util:include page="/jsp/fragment2include.jsp" servletcontext="<%= application %>">
<liferay-util:param name="someParam" value="<%= someParam %>" />
</liferay-util:include>
Then, in the included JSP, to get the parameter:
<%
String someParam = ParamUtil.getString(request, "someParam ");
%>
It won't work without specifying the serviceContext with the application object.
According to : https://portal.liferay.dev/docs/7-1/tutorials/-/knowledge_base/t/using-liferay-util-include:
The servletContext refers to the request context that the included JSP should use. Passing <%= application %> to this attribute lets the included JSP use the same request object as other objects that might be set in the prior JSP.
Kind regards.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™