In this post I just want to mention the value of 'request.getContextPath()' in liferay 7.
Before 7 'request.getContextPath()' return the name of custom portlet project.
Now this time it is returning
/o/base package name
Here '/o' appended with our base package name.
Suppose I gave "org.liferayasif.restautrant" package name at the time of creation of
liferay module project then
'request.getContextPath()' will return : '/o/org.liferayasif.restautrant'
if we want to display our module project name instead of package name we have to add one line in 'bnd.bnd' file and the code is
Web-ContextPath: /custom-module-project name
Web-ContextPath: /RestaurantProject (RestaurantProject is my module project name)
now the value return by
'request.getContextPath()' will be '/o/RestaurantProject'
RestaurantProject is my module project name.
'request.getContextPath()' having lots of use but I am using it to display my custom image that I stored inside module portlet.
I created one folder namely 'images' and the path is
'/META-INF/resources/images'
inside this images folder I stored my images and displaying in jsp pages.
Code to display images in my jsp page is
<img src="<%= request.getContextPath() %>/images/menu_list4.jpg">
if you don't want to use request.getContextPath() then you can directly write your porlet name with prefix '/o'.
Like this
<img src="/o/custom-module-porltet-name/images/menu_list.jpg" alt="problem">
<img src="/o/RestaurantProject/images/menu_list.jpg" alt="problem">
RestaurantProject: is my custom module portlet name.
Where 'menu_list.jpg' is my pic name.
Before 7 'request.getContextPath()' return the name of custom portlet project.
Now this time it is returning
/o/base package name
Here '/o' appended with our base package name.
Suppose I gave "org.liferayasif.restautrant" package name at the time of creation of
liferay module project then
'request.getContextPath()' will return : '/o/org.liferayasif.restautrant'
if we want to display our module project name instead of package name we have to add one line in 'bnd.bnd' file and the code is
Web-ContextPath: /custom-module-project name
Web-ContextPath: /RestaurantProject (RestaurantProject is my module project name)
now the value return by
'request.getContextPath()' will be '/o/RestaurantProject'
RestaurantProject is my module project name.
'request.getContextPath()' having lots of use but I am using it to display my custom image that I stored inside module portlet.
I created one folder namely 'images' and the path is
'/META-INF/resources/images'
inside this images folder I stored my images and displaying in jsp pages.
Code to display images in my jsp page is
<img src="<%= request.getContextPath() %>/images/menu_list4.jpg">
if you don't want to use request.getContextPath() then you can directly write your porlet name with prefix '/o'.
Like this
<img src="/o/custom-module-porltet-name/images/menu_list.jpg" alt="problem">
<img src="/o/RestaurantProject/images/menu_list.jpg" alt="problem">
RestaurantProject: is my custom module portlet name.
Where 'menu_list.jpg' is my pic name.
No comments:
Post a Comment