Forums

RSS RSS
RE: Problem displaying image in a JSP!!! (.war portlet) Flat View
Threads
Hi,
I've got a little problem in a portlet: I want to display in a JSP an image but I think I'm using the wrong way... In the JSP I use this tag:

<img src="/ext/ext-web/tmp/WEB-INF/smile.jpg">

but ,in the JSP page, the result is a white small icon with a red cross in the middle...
So I wanna ask if:

-is there any default folder to store the images that i want to use in mw JSP?
-in the property 'src' of the tag image I would like to use a relative path...but I don't know if the one
I use is the right one...

Thanks for your advice!!!
Flag Flag
RE: Problem displaying image in a JSP!!!
12/14/07 12:02 PM as a reply to Fabio Paroni.
Hi Fabio,

I had the same problem and resolved it by placing images in the server's directory structure as opposed to the portlet's. I'm using apache-tomcat and have it downloaded under:
C:\apache-tomcat-5.5.25\

In it there is a folder called "webapps" and I created a subfolder for my images there
C:\apache-tomcat-5.5.25\webapps\portal_content\img

From the portlet JSP (i.e. view.jsp) I refrence the image as such:
<img src="/portal_content/img/my_image.gif">

Hope this helps.
Flag Flag
RE: Problem displaying image in a JSP!!!
12/15/07 9:59 AM as a reply to Fabio Paroni.
You can look how Liferay stores the images (a lot of them are in the theme) and use the same technology.
Flag Flag
RE: Problem displaying image in a JSP!!! (.war portlet)
2/8/08 2:26 AM as a reply to Roman Hoyenko.
Hello all,

I have a very similar problem, I'm trying to display an image in a .war standalone portlet. Inside my portlet project the image path is WebContent/html/image/name.png. I tried to do it as Liferay does in other places but is not working. Nothing is shown. The only way that it works is to put the full path: <img src="http://localhost:8080/Indicator/html/image/indicator_good.png" />, but this way it will depend on the server I place the portlet. Indicator is my portlet name.

I tried these three options:
1<img src="/html/image/name.png" />
2
3<img src="/Indicator/html/image/name.png" />
4
5<img src="<%= request.getContextPath() =>/html/image/name.png" />

And no one of them is working. In the last one, request.getContextPath() returns an empty String. Do I need to define something first in other place to make request.getContextPath() works? Anyway I also need to look for the image from a template so, there I won't be able to use request.getContextPath().

Is there anything different when you are working in an external project for a standalone .war portlet?

Thanks in advance!
Flag Flag
RE: Problem displaying image in a JSP!!! (.war portlet)
2/11/08 2:51 PM as a reply to Daniel Rodriguez.
<img src="<%=renderRequest.getContextPath()%>/images/loading.gif"

worked for me.
Image was inside the war in /images/loading.gif
Flag Flag
RE: Problem displaying image in a JSP!!! (.war portlet)
2/12/08 12:25 AM as a reply to Roman Hoyenko.
It works!!!

Thanks a lot!!
Flag Flag
RE: Problem displaying image in a JSP!!! (.war portlet)
3/28/08 8:06 AM as a reply to Roman Hoyenko.
Roman Hoyenko:
<img src="<%=renderRequest.getContextPath()%>/images/loading.gif"

worked for me.
Image was inside the war in /images/loading.gif


This works not for me emoticon

I'vo got Error: "renderRequest cannot be resolved"
Flag Flag
RE: Problem displaying image in a JSP!!! (.war portlet)
7/11/08 12:30 AM as a reply to Roman Hoyenko.
I get the right context path - but still image is not visible.

Do we need to set something i web.xml or portlet.xml to make it work.

I guess its related to this my top URL, which is: http://localhost:8080/user/joebloggs/3

and context path is : my-context
so this becomes:
http://localhost:8080/my-context/images/date_icon.gif

thats why it may not be accessing the image
Flag Flag
RE: Problem displaying image in a JSP!!! (.war portlet)
11/7/08 7:42 AM as a reply to macario sm macario.
Hi,

I had the same problem. my fault was , that i didn't imported a taglib:
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

and then
<img src="<%=request.getContextPath()%>/img/image.jpg"/>

worked.

I hope this helps.
Flag Flag
RE: (RESOLVED) Problem displaying image in a JSP!!!
2/19/10 10:19 AM as a reply to Fabio Paroni.
I have the same problem.

Tried to use
1<img id="dukeimg" src="<%=renderResponse.encodeURL(renderRequest.getContextPath() + "/images/close.gif")%>"/>


or

1<img src="<%=request.getContextPath()%>/images/close.gif"/>




Both versions generate the same code "
1<img src="/infoserver/images/close.gif"/>
"


When using this the error
118:01:20,406 INFO  [STDOUT] 18:01:20,406 WARN  [PortalImpl] Current URL /web/guest/images/close.gif generates exception: null

disappears, but the images arent displayed.

Any idea?





PS.: Used the lib
1<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
2
3<portlet:defineObjects />
Flag Flag
RE: (RESOLVED) Problem displaying image in a JSP!!!
2/22/10 10:43 AM as a reply to Daniel H..
problem solved!

The portlet name etc. (configuration in web.xml/portlet.xml) has to be the same as the .war achieve.

After matching these

1<img src="<%=request.getContextPath()%>/images/close.gif"/>


works fine.
Flag Flag