• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling js file from jsp.

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
im using tomcat 4.0
i have a 'js' file which i want to include in a jsp file..how shld i give the path for the js file ??
i have kept the jsp files in the direcory named jsp and js files in a directory named js
the directory structure is
test // context path
|
| - Jsp
|
| - js
it works properly on html files..
i have tried everything like
<script language="JavaScript" src="../js/test.js">
<script language="JavaScript" src="/test/js/test.js" >
in the jsp file to include the js but all in vain
can any1 help me ?? im not sure where to post to doubt..is it anything related to tomcat setting ??
thanks
raj
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you do a view source on the html page that is written to your browser what do you see where the included script is supposed to be?
Bill
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi bill,
thanks for the reply..i wll tell u something.
I copied the source of the jsp page which is shown on the browser (right click,view source select all) and saved it as a html file..Later I executed this file from outside the server environment, i.e by giving the file path on the browser like d:\tomcat\...\jsp\copied.html
and found i working..i think there is some prob with my server setting but i donno wat to do !!! ..im using tomcat 4.0 on Win NT..
and in my first posting, wat i meant by 'html working properly' is html file working outside the server environment..
thanks
raj
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi bill,
I solved it..The culprit was the name of the 'js' directory..The name of my js directory was "Js" not "js" so i shld have given the src of js file as

<script .... src = "../JS/test.js">
</script>
i donno why ???
I have one more situation..im using two js files in the same "Js" directory..by giving the above <script src ..> I was able to access the one js file but the second one is not getting inlcuded..huh !! im tired ...
thanks for ur reply
raj
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can add Two or more .js files Like..
<script language='javascript' src='../JS/validations.js'></script>
<script language='JavaScript' src='../JS/datevalidate1.js'></script>
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yep, i tried that !! i guess, my tomcat doesnt like 2 js files in a jsp file...i copied the content of the second js file into the jsp and is working properly but i dont like this approach.. hope my tomcat will accept the 2 js file soon..
raj.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
as I've had to notice in a relative url in html the relative part is evaluated like that:
http://host:port/relative_part.
In a web application it's a little different :
http://host:port/context/relative_part.
But both have their root at context directory.So for html it's normal to write Js/test.js, no mention to tbe context needed.
Good bye.
[ March 17, 2003: Message edited by: Ivan Matmati ]
[ March 17, 2003: Message edited by: Ivan Matmati ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic