This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JSF and the fly likes Several folders for JSP in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Several folders for JSP in JSF" Watch "Several folders for JSP in JSF" New topic

Several folders for JSP in JSF

David Salaete

Joined: Aug 27, 2008
Posts: 19

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.

There are 10 types of people: Those who understand binary code and those who don�t.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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 "", then the relative URL "/images/1.jpg" will point to "". If there is no leading slash, then it will be relative to the current root. E.g. "images/1.jpg" will point to "". If you want to get a directory up, add "../" to the relative URL. E.g. "../images/1.jpg" would then point to "".

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 Salaete

Joined: Aug 27, 2008
Posts: 19
You are Ok.

Thank you very much.
It is sorta covered in the JavaRanch Style Guide.
subject: Several folders for JSP in JSF
jQuery in Action, 3rd edition