• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

image url in portlet

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 3
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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" />
 
Lookout! Runaway whale! Hide behind this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic