Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Python Continuous Integration and Delivery this week in the Python 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Several folders for JSP in JSF  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I�m trying to develop a JSF appliation, and I�ve decided to divide
JSP files in several groups of folders. (web/products/, web/users/... you know.)

Well, my problem is that when I want to refer an image, or a css, I cannot put a relative url because I cannot write someting like this:
<%
String CONTEXT=request.getContextPath();
%>
...
<h:graphicImage value="<%=CONTEXT%>/pages/img/logo.gif"></h:graphicImage>

It fails!!

or even
<h:graphicImage value="#{anyBean.imageUrl}"></h:graphicImage>

It fails, too.

So, �its necessary to put every jsp in the same folder to avoid this?



please help!! And forgive my "survival" English.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to learn about relative paths.

The leading slash in a relative URL will point to the domain root. If this page is requested by for example "http://example.com/webapp/pages/page.jsf", then the relative URL "/images/1.jpg" will point to "http://example.com/images/1.jpg". If there is no leading slash, then it will be relative to the current root. E.g. "images/1.jpg" will point to "http://example.com/webapp/pages/images/1.jpg". If you want to get a directory up, add "../" to the relative URL. E.g. "../images/1.jpg" would then point to "http://example.com/webapp/images/1.jpg".

It is almost the same as file system paths. There is absolutely no need to get and inline context paths, unless you want an absolute path which is independent from the environment.
[ August 27, 2008: Message edited by: Bauke Scholtz ]
 
David Carrascal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are Ok.


Thank you very much.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!