I have a simple JSR 286
Portlet that displays a user manual (pure HTML
code, not JSP
).
Actually, my doView
method, just contains this :
public class UserManualPortlet extends GenericPortlet
{
@Override
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException
{
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(
"/html/usermanual.html");
rd.include(request, response);
}
}
This works as expected, however I'm having trouble when including images. I'm aware that the path to images should be something like :
<img src='<%=renderResponse.encodeURL(renderRequest.getContextPath() + "/html/image.jpg")%>'/>
However, my HTML file containing the user manual is used elsewhere, so I would like to preserve it as a pure HTML file.
Is there a way to dynamically replace my classic images urls
by something like the example above ? Perhaps using the PrintWriter
of the response ?
If such thing is not possible, I thing I would need to generate a JSP
file during my Maven
build.
Any solution or ideas are welcome.
With JSR-268 portlets you have a better way of referencing resources: create
ResourceURL
usingrenderResponse.createResourceURL()
and then you set theresourceID
in theResourceURL
. That should give more consistent results across all portlet containers.That said, if you want to modify the generated content from your
usermanual.html
but you don't want to convert it to a JSP then, instead of using a request dispatcher, I would load the file contents on my own, parse it at the same time that I do the URL replacements and then print all the contents to the portlet's response.