Connecting Tech Pros Worldwide Help | Site Map

file path for external js

Asad Khan
Guest
 
Posts: n/a
#1: Jul 23 '05
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!
Klaus Johannes Rusch
Guest
 
Posts: n/a
#2: Jul 23 '05

re: file path for external js


Asad Khan wrote:
[color=blue]
> 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.[/color]

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
KlausRusch@atmedia.net
http://www.atmedia.net/KlausRusch/
Asad Khan
Guest
 
Posts: n/a
#3: Jul 23 '05

re: file path for external js


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!
Klaus Johannes Rusch
Guest
 
Posts: n/a
#4: Jul 23 '05

re: file path for external js


Asad Khan wrote:[color=blue]
> 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.[/color]

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
KlausRusch@atmedia.net
http://www.atmedia.net/KlausRusch/
Closed Thread