This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes calling .js in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "calling .js in jsp" Watch "calling .js in jsp" New topic
Author

calling .js in jsp

Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Hi ,

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

Anything i'm missing ?


Thanks,
Sherif
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
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

Joined: Mar 05, 2007
Posts: 483

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

Joined: Oct 08, 2008
Posts: 492
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

Joined: Mar 05, 2007
Posts: 483

I tried this but it;s not working too !!!
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
You are getting any script errors ? if so send that

Try to put some alert(); statement inside ds_sh()
Brijesh Verma
Greenhorn

Joined: Apr 20, 2009
Posts: 19
<script type="text/javascript" src="<%= request.getContextPath() %>/js/calender.js"></script>
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Brijesh Verma wrote: <script type="text/javascript" src="<%= request.getContextPath() %>/js/calender.js"></script>


This is not working too !!?
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Mar 05, 2007
Posts: 483

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

Joined: Nov 08, 2001
Posts: 15376
    
    6
No. "include it" was referring to the closing script tag.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60791
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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

Joined: Jan 10, 2002
Posts: 60791
    
  65

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

Joined: Nov 08, 2001
Posts: 15376
    
    6
Some browsers will allow you to drop the closing tag, but most browsers do not allow it. Use it.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling .js in jsp
 
Similar Threads
Question on BUTTON name/value pairs sent from JSP
layout and multibrowser hell
jquery accordion is causing jquery treeview picker to breakup
servlets/jsp
using Multiple submit buttons.