wood burning stoves*
The moose likes JSP and the fly likes relative path confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "relative path confusion" Watch "relative path confusion" New topic
Author

relative path confusion

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi All,


i have a.jsp & b.jsp under root

i am including b.jsp in a.jsp like below
------------------------------------
a.jsp
-----
<%@include file="/b.jsp" %>//fine it is working

my doubt is when i do like below also it is working how?

<%@include file="../b.jsp" %>//

please anyone can explain me?

Thanks & Regards,
seetharaman
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The first makes it relative to the root of the webapp.
The second makes it relative to the current file.

The first, in my opinion, is a better approach.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hai Ben,

please can you explain in details?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The first "/b.jsp" says to the server "Look for b.jsp in the root of this web application". In this case, it doesn't matter where a.jsp is. You could move it from "/" to "/pages/" to "/pages/directoryToHoldPageA/" or any other sub-directories and the app would still know how to find page B.jsp.
This link would only be broken if you were to move B.jsp.
You can move A.jsp to any location within the application and it would still know where to find B.jsp.

The second, is relative to the location of A.jsp.
The ".." is the symbol for parent directory.
So "../B.js" says to the server "Look one directory higher than the one that I (A.jsp) am in for a page named B.jsp". If you move either A.jsp, or B.jsp, and the move doesn't result in B.jsp being in the parent of the directory that holds A.jsp, the link will be broken.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks a lot BEN
 
Don't get me started about those stupid light bulbs.
 
subject: relative path confusion
 
Similar Threads
Need help: jsp: include relative path question!
jsp:include
page relative vs file relative [ include action vs include directive]
Difference JSP File & JSP Page
include action vs. include directive