• 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

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

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
pankaj patil
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried that but still same
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pankaj patil wrote:I have tried that but still same


Then you did it incorrectly.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have tried that but still same



code ?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muhammad Saifuddin wrote:code ?

I think we're supposed to use a crystal ball.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this first--not all browsers handle body-less script tags correctly.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic