Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
pankaj patil
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64691
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I have tried that but still same
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64691
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pankaj patil wrote:I have tried that but still same

Then you did it incorrectly.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried that but still same


code ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64691
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muhammad Saifuddin wrote:code ?
I think we're supposed to use a crystal ball.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this first--not all browsers handle body-less script tags correctly.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64691
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64691
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Ankit Garg
Sheriff
Posts: 9510
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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...
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic