Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

calling .js in jsp  RSS feed

 
S Shehab
Ranch Hand
Posts: 492
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I'm trying to call .js file in my jsp but it;s not working here is the code :

Anything i'm missing ?
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your js Folder ?. In unix machine or windows machine. If in unix add '/' prefix <script type="text/javascript" src="/js/Calendar.js">

For Import use the head section not body

 
S Shehab
Ranch Hand
Posts: 492
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meet Gaurav wrote:Where is your js Folder ?. In unix machine or windows machine. If in unix add '/' prefix <script type="text/javascript" src="/js/Calendar.js">

For Import use the head section not body


It's on Windows machine , here is the full path for my js
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D:\folder1\eclipse\workspace\Audit\WebContent\js\Calendar.js

So your HTML is D:\folder1\eclipse\workspace\Audit\WebContent\HTML.html. Then use

<head>
<script type="text/javascript" src="js/Calendar.js">
</head>
 
S Shehab
Ranch Hand
Posts: 492
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this but it;s not working too !!!
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are getting any script errors ? if so send that

Try to put some alert(); statement inside ds_sh()
 
Brijesh Verma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<script type="text/javascript" src="<%= request.getContextPath() %>/js/calender.js"></script>
 
S Shehab
Ranch Hand
Posts: 492
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brijesh Verma wrote: <script type="text/javascript" src="<%= request.getContextPath() %>/js/calender.js"></script>


This is not working too !!?
 
S Shehab
Ranch Hand
Posts: 492
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even i tried to put the javascript code between the <script> blocks it's not working too ...

Anything i'm missing ?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with script tags you have to have a closing script tag



If you do not include it, it will not work.

Eric
 
S Shehab
Ranch Hand
Posts: 492
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:with script tags you have to have a closing script tag



If you do not include it, it will not work.

Eric


Hi Eric,

Do yo mean <@include file = "" /> ?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. "include it" was referring to the closing script tag.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sherif Shehab wrote:
Eric Pascarello wrote:with script tags you have to have a closing script tag



If you do not include it, it will not work.

Eric


Hi Eric,

Do yo mean <@include file = "" /> ?

No. He meant to include the closing tag.

Have you read the JSP FAQ entry on this issue? You should be using server-relative URLs in a JSP.
 
S Shehab
Ranch Hand
Posts: 492
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok i'll read it , by the way i wrote this tag <script type="text/javascript" src="js/Calendar.js"> in another jsp and it works fine !!! so what do you think i'm missing ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are missing the fact that "current directory" is usually not meaningful in JSPs and you need to use server-relative addressing rather than page-relative addressing. It's all explained in the FAQ.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some browsers will allow you to drop the closing tag, but most browsers do not allow it. Use it.

Eric
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!