This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Kubernetes in Action and have Marko Luksa on-line!
See this thread for details.
Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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
 
Author and ninkuma
Marshal
Posts: 66352
155
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
Posts: 66352
155
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.
 
Ranch Hand
Posts: 1325
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
Posts: 66352
155
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.
 
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
Posts: 66352
155
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
Posts: 66352
155
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.
 
Sheriff
Posts: 9610
37
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...
 
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
Boost this thread!