aspose file tools*
The moose likes Portals and Portlets and the fly likes image url in portlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "image url in portlet" Watch "image url in portlet" New topic
Author

image url in portlet

Pablo Olmos
Greenhorn

Joined: Aug 20, 2004
Posts: 10
Hello, I'm having a real hard time by trying to display an image with the <img> tag in a portlet. I can't seem to generate the URL appropriately

This is the closest I've come to generating the right url in the doView() method:


I even tried to encode it like so:

but that throws and Illegal argument exception. becase the url generated is something like this:

and the encodeURL method requires the path to start with a "/" or contain "://".

the bottom line question is: how can i get an url for an image that is included in my war archive?

thanks,

Pablo
osman cinar eren
Ranch Hand

Joined: Jan 25, 2005
Posts: 78
you can do the following:
if your context is wps(as in the case with IBM Websphere), you can use:
<a href="/wps/images/page.gif">click to see page.gif</a>


hope this helps..


SCJP/SCWCD
Jose Pereira
Greenhorn

Joined: Dec 10, 2002
Posts: 12
havent tryed bun the spec says that for u not to have problem whith URL encoding u should use the encodeURL() method to get the url specific to the conteiner u use ....

PLT.12.1.2 Encoding of URLs
Mehdi Chaouachi
Ranch Hand

Joined: Jul 02, 2003
Posts: 87
I had the same problem with liferay earlier. While I didnt find a perfect solution, I found a temporary one.

You can place your images in the liferay folder (under tomcat) and then use the "/" in your image. I thik this is a known problem with liferay, I dont know if they have solved it yet or not.


Mehdi Chaouachi<p>Sun Certified Java Programer (1.4)<br />Sun Certified Web Component Developer (1.4).<br />Sun Certified Mobile Application Developer.
pegel van de Wiel
Greenhorn

Joined: Jun 09, 2011
Posts: 3

Also using Liferay and stubled upon this old thread.
Without knowing too much about it, the following worked for me

All within the same .jsp:

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<portlet:defineObjects />

<img src='<%=renderResponse.encodeURL(renderRequest.getContextPath() +
"/images/earth.jpg")%>'
alt="Earth" />
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: image url in portlet