• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling .js in jsp

 
Sherif Shehab
Ranch Hand
Posts: 485
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

 
Sherif Shehab
Ranch Hand
Posts: 485
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>
 
Sherif Shehab
Ranch Hand
Posts: 485
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>
 
Sherif Shehab
Ranch Hand
Posts: 485
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 !!?
 
Sherif Shehab
Ranch Hand
Posts: 485
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
 
Sherif Shehab
Ranch Hand
Posts: 485
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
Pie
Posts: 64959
86
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.
 
Sherif Shehab
Ranch Hand
Posts: 485
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
Pie
Posts: 64959
86
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic