This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Several folders for JSP in JSF" Watch "Several folders for JSP in JSF" New topic
Author

Several folders for JSP in JSF

David Salaete
Greenhorn

Joined: Aug 27, 2008
Posts: 19
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.


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 "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 Salaete
Greenhorn

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


Thank you very much.
 
jQuery in Action, 2nd edition
 
subject: Several folders for JSP in JSF