By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

file path for external js

P: n/a
Hi, I have the following directory structure

index.jsp
a.js
b.js
|
|--/templates
|
|--/blah.jsp

Now blah .jsp is included INSIDE index.jsp.
In blah.jsp I have a button that calls a function inside b.js.
In index.jsp I have following code inside head tags:

<script src="a.js"></script>
<script src="b.js"></script>

and I figured since blah.jsp is included inside index.jsp, I should be
able to access the javascript methods with ease. But its not happening
that way. I get an error (object expected in the line that has button in
it). BTW, its not a problem in my JS or JSP code, because if I put the
js file's contents inside blah.jsp, then it works like a charm!

So what am I doing wrong?

I also tried moving my script import statements inside blah.jsp as:

<script src="../../a.js"></script>
<script src="../../b.js"></script>

But this doesn't seem to work either?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Asad Khan wrote:
Hi, I have the following directory structure

index.jsp
a.js
b.js
|
|--/templates
|
|--/blah.jsp

Now blah .jsp is included INSIDE index.jsp.
In blah.jsp I have a button that calls a function inside b.js.


How the page is constructed does not matter since the browser has no
visibility on where the different components were pulled from.

If you suspect that the JavaScript code is not loaded, check the server
logs to see if a.js and b.js have been accessed by the browser, or look
at the HTTP headers with a header sniffer of your choice, such as Live
HTTP headers for Firefox.

--
Klaus Johannes Rusch
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 23 '05 #2

P: n/a
Never mind, I figured it out. The jsp page was called from my servlet,
and the javascript files were one folder up from the servlets dir.
Therefore I needed one ../ and not two ../../ like I was trying.

Thanks to myself.

No Im kidding, just in case someone else is going through the same thing
in future.

Asad

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3

P: n/a
Asad Khan wrote:
Never mind, I figured it out. The jsp page was called from my servlet,
and the javascript files were one folder up from the servlets dir.
Therefore I needed one ../ and not two ../../ like I was trying.


If the application does not need to be relocatable to another directory
path, it may be easier to refer to other resources by a path relative to
the server root, that is

/where/the/thing/resides/file.js

Of course that assumes that you know the path where other resources will
be placed already.

--
Klaus Johannes Rusch
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.