Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Fabio Paroni
(RESOLVED) Problem displaying image in a JSP!!!
February 12, 2008 10:05 AM
Answer

Fabio Paroni

Rank: New Member

Posts: 4

Join Date: November 22, 2007

Recent Posts

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!!!
Isa G
RE: Problem displaying image in a JSP!!!
December 14, 2007 12:02 PM
Answer

Isa G

Rank: New Member

Posts: 5

Join Date: December 10, 2007

Recent Posts

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.
Roman Hoyenko
RE: Problem displaying image in a JSP!!!
December 15, 2007 9:59 AM
Answer

Roman Hoyenko

Rank: Liferay Master

Posts: 868

Join Date: October 8, 2007

Recent Posts

You can look how Liferay stores the images (a lot of them are in the theme) and use the same technology.
Daniel Rodriguez
RE: Problem displaying image in a JSP!!! (.war portlet)
February 8, 2008 2:26 AM
Answer

Daniel Rodriguez

Rank: Junior Member

Posts: 38

Join Date: August 9, 2006

Recent Posts

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!
Roman Hoyenko
RE: Problem displaying image in a JSP!!! (.war portlet)
February 11, 2008 2:51 PM
Answer

Roman Hoyenko

Rank: Liferay Master

Posts: 868

Join Date: October 8, 2007

Recent Posts

<img src="<%=renderRequest.getContextPath()%>/images/loading.gif"

worked for me.
Image was inside the war in /images/loading.gif
Daniel Rodriguez
RE: Problem displaying image in a JSP!!! (.war portlet)
February 12, 2008 12:25 AM
Answer

Daniel Rodriguez

Rank: Junior Member

Posts: 38

Join Date: August 9, 2006

Recent Posts

It works!!!

Thanks a lot!!
Martin Wolfgang Kirst
RE: Problem displaying image in a JSP!!! (.war portlet)
March 28, 2008 8:06 AM
Answer

Martin Wolfgang Kirst

Rank: New Member

Posts: 1

Join Date: March 28, 2008

Recent Posts

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"
macario sm macario
RE: Problem displaying image in a JSP!!! (.war portlet)
July 11, 2008 12:30 AM
Answer

macario sm macario

Rank: New Member

Posts: 2

Join Date: July 10, 2008

Recent Posts

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
Jens Ferring
RE: Problem displaying image in a JSP!!! (.war portlet)
November 7, 2008 7:42 AM
Answer

Jens Ferring

Rank: New Member

Posts: 5

Join Date: October 23, 2008

Recent Posts

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.
Daniel H.
RE: (RESOLVED) Problem displaying image in a JSP!!!
February 19, 2010 10:19 AM
Answer

Daniel H.

Rank: New Member

Posts: 8

Join Date: February 12, 2010

Recent Posts

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 />
Daniel H.
RE: (RESOLVED) Problem displaying image in a JSP!!!
February 22, 2010 10:43 AM
Answer

Daniel H.

Rank: New Member

Posts: 8

Join Date: February 12, 2010

Recent Posts

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.
Andy Harb
RE: (RESOLVED) Problem displaying image in a JSP!!!
February 24, 2011 11:23 AM
Answer

Andy Harb

Rank: Junior Member

Posts: 64

Join Date: October 22, 2009

Recent Posts

When i use the "request.getContextPath()" I get the correct path for my portlet when I am viewing the view.jsp page. However, as soon as i go to the Preferences and look at my custom setup.jsp the "request.getContextPath()" returns a "/".

I am importing the correct taglib and have the objects defined. Any assistance or pointers would be greatly appreciated.

Liferay 5.2.3

Thanks
Andy
Vishnu Sistla
Steps to add an images to portlet JSP.
April 7, 2011 1:24 PM
Answer

Vishnu Sistla

Rank: New Member

Posts: 2

Join Date: March 11, 2011

Recent Posts

Steps:
1.Add images folder to docroot (docroot\images).
2. Access the image in JSP using the following.
<img src="<%=request.getContextPath()%>/images/abc.png"/>

Done!. Good Luck!
Nguyen Le
RE: Steps to add an images to portlet JSP.
May 29, 2012 8:45 AM
Answer

Nguyen Le

Rank: New Member

Posts: 11

Join Date: April 24, 2012

Recent Posts

Please help me!!!

I have stored pictures on "C:\\images\\logo.jpg".
In view.jsp of my portlet, I want display a image in above locate by code:
<img width="120" height="120" src="logo.jpg" alt='Image can't display'/>

But I can't see this image in my page.(The string "Image can't display' can't put in browser)
Please tell me this error.
karthik reddy
RE: Steps to add an images to portlet JSP.
February 7, 2014 4:01 AM
Answer

karthik reddy

Rank: Junior Member

Posts: 29

Join Date: April 8, 2013

Recent Posts

Hi just follow the vishu steps
Create a one folder as images in your eclipse under docroot and paste your images.Try to read the images by giving the path like
<img src="<%=request.getContextPath()%>/images/banner_1.jpg"/>
If you want to do in VM file for example like logo change
<img src="$themeDisplay.getPathThemeImages()//logo/logo.jpg" width="960" />