Hello Behrang,

Well, that's not "strange behavior", it is exactly what one should
expect.  Keep in mind that your context is at:
http://localhost:8080/headertest

As the browser see it, it is one directory in from the root of the
web.  The server understands this as a context rather than just
another directory.  If you want to tell the server than you want to
reference a file from this same context, you need to provide the name
of the context in your linked path.

so instead of:
<a href="/home.jsp">home</a>

you need:
<a href="/headertest/home.jsp">home</a>

Now, you might as "well, what if I change the same of the context?"
"Now I am stuck with a hardcoded context path in my jsp."  There are a
couple solutions.

1. dynamically write in the context name at runtime so no matter what
context name you deploy your app under, it will always refer to the
correct context.

2. refer to your pages in a relative fashion.  When you reference "/",
you reference the root of the web.  However, if you just did "./",
that says "whatever directory I am in, start from there and find my
document."

3. deploy your app to the root of the web.  Look at Tomcat's ROOT
application and how it is deployed.

All solutions have their issues.  #1 hobbles you with having to place
all that dynamic writing of context's.  #2 makes you always have to
know what directory your page is in and how it is relative to all the
other pages.  And, if you move the page to another directory,
especially deeper or more shallow in the tree, you will have to modify
the links to point to the new relative locations of all the files.  #3
can be deceiving because it looks like the problem is solved, but if
you count on this solving your problem, you have to make sure that
everyone who installs your app does so as the root application and you
can't always count on that.

Another way to solve this issue is to use MVC where you have a servlet
mapping and some event handling system that knows where the pages are.
However, you still have to provide the reference to the  current
context in the link that points to your controller servlet.  So,
you'll never solve this issue fully, but you have a number of options
to go with to help deal with it.

Hope that helps.

Jake


Wednesday, September 18, 2002, 8:48:46 AM, you wrote:

BS> Hi

BS> I'm designing a new web application and I have stored my files in the 
D:\Tests\Web\HeaderTest directory and I have defined the following Context in the 
server.xml:

BS> <Context 
BS>       path="/headertest" 
BS>       docBase="D:\Tests\Web\HeaderTest" 
BS>       debug="0" 
BS>       privileged="true"
BS>  />

BS> I suppose this tells the Tomcat that the root directory for my webapp is 
D:\Tests\Web\HeaderTest or http://localhost:8080/headertest.

BS> But if I define a link in a page in my webapp such as:

BS> <a href="/home.jsp">Link </a> 

BS> it refers to a wrong document: http://localhost:8080/home.jsp which is unavailable.

BS> Does anybody know what's wrong with this?

BS> Also another problem is that when I include a file using the include action or 
even the include directive the links defined in the included document changes so they 
don't refer to their original
BS> destinations anymore. For example, I want a header.html to be included in all the 
pages throughout my web site but if I include the header.html in subdirectories of my 
web app, the links get
BS> broken.

BS> I have tried lots of guesses and I have read some parts of JSP 1.2 Spec that are 
about includes and ... but I have not found the answer.

BS> All helps are appreciated.
BS> Thanks in advance.



-- 
Best regards,
 Jacob                            mailto:[EMAIL PROTECTED]


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to