aspose file tools*
The moose likes Servlets and the fly likes Can't include .js file on jsp page controlled by front controller servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can Watch "Can New topic
Author

Can't include .js file on jsp page controlled by front controller servlet

pankaj patil
Ranch Hand

Joined: Dec 19, 2004
Posts: 98
i have a jsp page which is been forwarded from servlet using requet dispatcher
And in that jsp i have included js file using <script langauge="javascript" src="../script/util.js"/>
but the js is not getting loaded.Jsp page gives error when i call any of the function defined in the util.js file

Can any one help me out for same

regards
Pankaj


Regards,
Pankaj Patil
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Page-relative addressing is almost guaranteed to cause problems.

Use server-relative addressing beginning with the context path. See the JSP FAQ for more info.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
pankaj patil
Ranch Hand

Joined: Dec 19, 2004
Posts: 98
I have tried that but still same
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

pankaj patil wrote:I have tried that but still same

Then you did it incorrectly.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

I have tried that but still same


code ?


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Muhammad Saifuddin wrote:code ?
I think we're supposed to use a crystal ball.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Try this first--not all browsers handle body-less script tags correctly.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

David Newton wrote:Try this first--not all browsers handle body-less script tags correctly.

Good point -- I missed that. Few browsers will handle that.

The page-relative addressing will still be an issue. So both issues need to be fixed.

But since we haven't seen any updated code...
pankaj patil
Ranch Hand

Joined: Dec 19, 2004
Posts: 98
i have 2 option

1) by using jsp include
2) by using the request.getRealPath("/")

But in the above case i am showing him the path of my application which i don't want too.
And i am not getting why it is behaving in this way


Regards
Pankaj
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

pankaj patil wrote:i have 2 option

1) by using jsp include
2) by using the request.getRealPath("/")

What on Earth do JSP includes and getRealPath have to do with script files? Answer: nothing.

Just use the <script> tag properly and all will be fine.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Pankaj, what everyone is trying to tell you here is that don't use a relative path to point to your script. Use an absolute path starting from the context path. You can use EL to get the context path. Its something like this


The relative syntax will work on the basis of the request URL. If your relative path is correct on the basis of the location of the JSP, that doesn't mean that it will work...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

You can also use the HTML base tag to aid you. Specify the absolute path of the script file in question to avoid confusion. Use a browser based debugger like firebug to check for broken links to the JS


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't include .js file on jsp page controlled by front controller servlet