While working with portlets on different Portal Servers (WebSphere Portal Server, Liferay Portal Server), there are times when we need to construct a URL to a local file within the project. There are several ways to this but leveraging the Request objects has been something i’ve been playing around with. To save time, here are some output examples from different Request objects.
ResourceRequest and RenderRequest
Verified on: Liferay Portal and WebSphere Portal Server
URL example: http://localhost:8080/MyProjectName
Thus if you were to construct a URL to a local resource from a RenderRequest or a ResourceRequest, use the following calls above to build out your initial URL path, and add in the rest.
i.e. If you are building a Liferay Portlet and there is a /xml/data.xml in your docroot, you can build the full path “http://localhost:8080/MyProjectName/xml/data.xml”. Just ensure that the path added is from your web content directory housing everything accessible publicly.
TODO: This page will be updated as I add more different request/response objects for Portlets and Servlets.