Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Tomcat cannot found relative Image-Path / Context-Path

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

onTomcat 7 I have a Struts-Application.
From the jsp-pages I like to reference my images on a dynamic way. The images are stored under the directory

Tomcat_HOME/myweb/images/...

My META-INF/context.xml has already a path entry like this:

<Context path="/myweb">

Cause I have different paths in my struts-application I reference images by using absolute path-references.
I also tried to use relative-paths and context-relative-paths.

Now I try to reference all the images in a normal relative way, but it doesn't work for me all the time.


If I use <img src="/images/suchen.gif"

it takes me to http://localhost:8080/images instead of http://localhost:8080/myweb/images/....

If I use <img src="./images/suchen.gif"

that takes me to the path depending on the struts action, that changes during life-cycle, so it does not work all time.


Is there a common way on web.xml to map these urls ?

Otherwise I use the context-path in JSP and add the relative path to the context path...

Thanks








 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try <img src="images/suchen.gif"> (without the leading slash)?

The leading slash is from the root (localhost:8080)
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, do read this article about relative paths in the context of a web application https://coderanch.com/how-to/java/RelativeLinks
 
Timo Munich
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I already read this document as well as Tomcat-Documentation about Contexts.
I am new with Tomcat 7 and I could not believe there is no easy way to config the context-path or to reach the relative context.

Now I am going to use this way which will take me a lot of time, but I know its working.

To safe time for anybody who is looking for similary stuff I will post the entire line which shows how to reach images flexible in Tomcat from the relative context-path within JSP.
I am also using Message.properties.



 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you need to use <bean:message> for the image? At the end you need the context-path, doesn't
<img src="<%=request.getContextPath()%>/images/blabla.gif" width="100" height="100" />
 
Timo Munich
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote:Why do you need to use <bean:message> for the image? At the end you need the context-path, doesn't
<img src="<%=request.getContextPath()%>/images/blabla.gif" width="100" height="100" />



I need bean:message in subject to language the user has chosen. Some images have text on the images, so I need to load it dynamic.
Do you know any better implementation for this ?
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Back to the context path issue. Since you are using Struts, can't you use struts tags like "html:xxx"? For images would be <html:image ..... />
 
Timo Munich
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote:Back to the context path issue. Since you are using Struts, can't you use struts tags like "html:xxx"? For images would be <html:image ..... />



In fact, first I was already using <html:image and ><html:img src="< but I decided to change it because I did not find any good way to assign <bean:message.. tag to the <html:img without
using script-variables, like this snippet:


<html:img src="><%=request.getContextPath()%><bean.message .....> ../>


This seems to be very circular. I was casually reading there is a way with jstl or EL...but I did not find the time to read it all..
 
reply
    Bookmark Topic Watch Topic
  • New Topic