cancel
Showing results for 
Search instead for 
Did you mean: 

How to display images ?

Former Member
0 Kudos

Hello, I'm try to display a JSP page with some images.

In a Developer Studio I obtain a correct visualization but after deploy, on a http url, I see only a html structure of the file without images. I used this structure:

webContent: contains a jsp file

webContent/common: contains a gif files.

In a jsp file I refer the image with:

<img src="common/apri_inpopup.gif">

Where is my error ?

Thanks in advance

Gianfranco

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

Hi Gianfranco and everyone,

I passed through the same problem and figured out the root cause. Maybe Gianfranco is not interested in the answer more than 2 years later, but I was! So, for the record, the Quick Car Rental tutorial defines QuickOrderProcessorServlet as the root (/). This way every request is sent to servlet processing, even requests for images... The easier solution is defining the servlet as /action or something, and leave the root free for subfolders, as /images. This way the direct call suggested above will work as expected. For form processing, just put the attribute action="/action" on the forms and you'll be sent to the Servlet.

Former Member
0 Kudos

Hi Gianfranco,

I would recommend you to keep the images in your images directory and use the following

String imagePath = componentRequest.getWebResourcePath() + "/images/image.jpg"

and use the image path variable in the src attribute of the img tag

Former Member
0 Kudos

that's what i said. Can you let me know if you have added something new to my post.

Former Member
0 Kudos

Hi Prakash,

I've tried your solution but I've obtained an error: componentRequest is not a variable.

I think that it happens because I'm not use an Enterprise Portal component.

So, instead of componentRequest.getWebResourcePath() I try to use request.getContextPath()

but it doesn't give me a solution.

Another doubt: if I try display image with the url:

http://servername:port/contextroot/imagefolder/image.gif

I obtain the jsp but not the image.gif.

Gianfranco

Former Member
0 Kudos

What type of component are you writing?

Former Member
0 Kudos

I'm try to realize a J2EE project with Developer Studio in a similar manner of the Quick Car Rental tutorial. Then I writing an EJB project and a WEB project (which contains jsp, images, etc.).

Former Member
0 Kudos

have you tried <b>getServletPath()</b> method.

Former Member
0 Kudos

Yes, I tried getPathInfo() and getServletPath() but none of these resolved my problem. Unfortunately no images was present in J2EE Car Rental tutorial.

kenichi_unnai
Advisor
Advisor
0 Kudos

Hi,

Something like

request.getContextPath() + "/common/blah.gif";

should work.

Hope this helps,

Ken

former_member185706
Participant
0 Kudos

Hi Gianfranco,

did you try to request directly the URL of the image?

i.e. http://servername:port/contextroot/imagefolder/image.gif

And could you try and check the result pls with a simple jsp, containing only

<img src="imagefolder/image.gif" />

Regards

Bojidar

Former Member
0 Kudos

Hi Gianfranco,

You need some more coding. Let say images are stored in <b>dist->images</b> folder then your jsp will the have following code.

<b>

<% String image = componentRequest.getWebResourcePath() + "/images/image.gif"; %>
<img src="<%=image%>">

</b>

if the images are stored in the folder <b>dist->PORTAL-INF->images</b> folders then your jsp will have the following code.

<b>

<% String image = componentRequest.getPrivateResourcePath()() + "/images/image.gif"; %>
<img src="<%=image%>">

</b>