• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

simple relative path img

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
img src = "/image/myimg.jpg"
won't work because need context root

img src = "/currentContextRoot/image/myimg.jpg"

asp has ~ to get application (context root).

Is there a method to avoid having to specify context root. either jsp/java or html?
 
Marshal
Posts: 67366
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JSP 2.0:

${pageContext.request.contextPath}

prior to JSP 2.0:

<%= request.getContextPath() %>
 
Jack Adams
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is considered "best practice" or is there a "better" way?

Note: JSP is pre 2.0 (old)
 
Bear Bibeault
Marshal
Posts: 67366
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen a number of common practices:

1) In JSP 2.0, use of the JSTL <c:url> tag which handles all that for you is encouraged.

2) If not, the context path could be added to each URL as in:

<img src="${pageContext.request.contextPath}/images/pixel.gif"/>

or

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

3) Or, a <base> HTML tag is defined that sets the document "base" to the context path so that context-relative URLs can be used.
[ August 03, 2005: Message edited by: Bear Bibeault ]
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!