my dog learned polymorphism
The moose likes Struts and the fly likes Problem displaying images from Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem displaying images from "/"" Watch "Problem displaying images from "/"" New topic

Problem displaying images from "/"

Florent LOTHON

Joined: Feb 06, 2003
Posts: 7
I trie to display my image with the <html:img struts tag
In the application ressource properties i set the images like this :
And i would like to use it in any JSP :
/jsp/page1.jsp or /jsp/popup/popup1.jsp

but the image aren't displayed (path incorrect).
So i tried to display the images as this with the <a href html tag :
"myProject" = my project context (in the webapps tomcat directory)
And it works but, you should know it isn't good.
In another application, i haven't this problem but i don't know where is the difference between the two projects about this "/"path problem.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
You can use request.getContextPath()/img/xxx.img instead of hardcoding the context root.
This problem happens because the img directory cannot be relatively pointed from the location of the servlet class.
Hope this help.
[ March 30, 2004: Message edited by: Nicholas Cheung ]

SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Florent LOTHON

Joined: Feb 06, 2003
Posts: 7
I wasn't using the correct attribute of <html:img tag :
i was using srcKey instead pageKey.
So it works fine now
I agree. Here's the link:
subject: Problem displaying images from "/"
It's not a secret anymore!