Portlets should encode all resource URLs pointing to resources in the portlet application via this method in order to ensure that they get served via the portal application. Some portal/portlet-container implementation may require those URLs to contain implementation specific data encoded in it. Because of that, portlets should use this method to create such URLs.
The encodeURL method may include the session ID and other portal/portlet-container specific information into the URL. If encoding is not needed, it returns the URL unchanged. Portlet developer should be aware that the returned URL might not be a well formed URL but a special token at the time the portlet is generating its content. Thus portlets should not add additional parameters on the resulting URL or expect to be able to parse the URL. As a result, the outcome of the encodeURL call may be different than calling encodeURL in the servlet world.
As you can see its very difficult to understand how it works so i did some experiment to figure out the exact behavior
<%= renderResponse.encodeURL(renderRequest.getContextPath() + "filepathinsidewebmodule") %>
For example i want to include sampleimg.gif which is at the root of my web application i.e. at the same as that of WEB-INF then i can include it my application using this URL
<img src='<%= renderResponse.encodeURL(renderRequest.getContextPath() + "sampleimg.gif") %>'>
This JSP code will get converted into following HTML markup
In this the
/wps/PA_ResourceServingpart is the application context of the portlet which contains this URL.
You can find the context root of the portlet in two ways. While deploying the portlet in 6.1 it lets you set the context root for the portlet. You can find the context root of a portlet which is already installed by going to
/wp_profile/installedApps/DefaultNode/yourportlet.eardirectory and then inside META-INF there will be application.xml, open it and you will notice it is something like this
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Application_ID" version="1.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
As you can see in my case the ResourceServing.war file is installed at the
Inside your JSP you can find this context root by calling
encodeUrl()does not have any effect of the URL. But you should always include your URL