Your problem is almost certainly the <base> tag. Why do you have it there? The href in <base> will skew the way the browser looks at relative paths and make it so that they are not resolved to the URL in the location bar of the browser, but to the URL in the href of the <base> tag. Besides, the location makes no sense. You are pointing to a resource under WEB-INF which is impossible for a browser to access in the first place. Remove <base> and your problems are (mostly) solved.


More below...

At 10:13 AM 12/29/2004 +0800, you wrote:
>Hi again ! ^^
>here is the generated html:
><html lang="en">
> <head>
> <base href="http://localhost:8080/val/WEB-INF/jsp/residential_search.jsp";>
>
> <title>Residential Search</title>
> <script src="/val/js/resid.js" type="text/javascript"></script>
> <script>
>.......
>.......
>.......
>
>which is using absolute path so no problem here,
>but if I use relative path:
>"<script src="/js/resid.js" type="text/javascript"></script>"


Was that a typo? You are calling this a "relative path", but "/js/resid.js" is using an absolute path. Probably just a typo, but I want to make sure you understand what you are saying here. More below...

>then I can reference the .js
>
>and here is the directory structure:
>{Tomcat home}/webapps/val
>                                     |---- /js
>                                     |---- /WEB-INF
>                                                   |------- /jsp (<--
>which holds all my .jsp)
>
>and the url in the browser is:
>
>http://localhost:8080/val/area_selection.do
>
>
>so the /js is directly under the root folder, and
>"<script src="/js/resid.js" type="text/javascript"></script>"
>should work, isn't it??
>

Ok, I guess you actually don't know what a relative path is because you keep making the same "typo". You have two problems:

1. Remove the <base> tag. Never, ever use that abomination unless you have a REALLY good reason to do so. Based on how you are using it, I'm not even sure you understand what it does?

2. A relative path does *not* have a "/" prefix. That is an absolute path pointing to the root of the webserver. Based on the sample URL, your context is "/val". As such, using "/js/resid.js" would look for the .js file in a directory at the same level as "val", meaning it won't find the "js" directory underneath "val". Here's where "/js/resid.js" would point...

http://localhost:8080/js/resid.js

That's, obviously, not what you want. Do one of two things (assuming you've removed the <base> tag already!)....

1.  Use the absolute path "/val/js/resid.js"
2.  Use the relative path "js/resid.js"

Either one will work. The reason to use #2 is that you don't have to hardcode the context path. The reason to use #1 is if you expect to be accessing your area_selection.do struts action at some directory level deeper into your context path. Take, for instance...

http://localhost:8080/val/admin/area_selection.do

Now if you are using #2, the browser would look in the following location for the .js resource...

http://localhost:8080/val/admin/js/resid.js

That's, obviously, not what you want. However, if you had used #1, you wouldn't have noticed a difference in functionality because it would look in the same location for the .js file as it did when area_selection.do wasn't under the "admin" directory. This is the freedom that absolute paths provide. However, be careful not to hardcode the name of your context (as I mentioned in another email) because the context name might change. If and when it does, your absolute path will cease to work. So, in a JSP, use....

"<%=request.getContextPath()%>/js/resid.js"

Now you have an absolute path that will work no matter the URL in the browser location bar. Plus, if you ever decide to switch context names, or use the default context which is an empty path, your resource will continue to be found with no need for code changes.

>but now it seems I can only use absolute path, which is not a very big
>deal but it would be nice if someone help me to sort it out ..... ^^
>

Redux:

Absolute path examples...
"/myapp/js/my.js"
"http://localhost:8008/myapp/js/my.js";

relative path example, assuming the URL is something like http://localhost:8008/myapp/hello.do and the "js" directory is in the root of the context...
"js/my.js"


Notice the lack of the prefixed "/" in the latter example.

>thanks

I really do hope you understand this stuff after my explanation above. It took me a while to type. I hope it was worth it!


Jake



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



Reply via email to