• 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

relative path confusion

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,
I am having lots of confusion over setting up relative paths for my pages.

I have the following jsp.



I want to pass contextPath to the javascript function shown below.



But I am getting error because its trying to pass "/actualContextPathName".

I would like to know how to use context path if i need to include...

1) Image
2) JS
3) Html
4) Another Jsp
5) css
6) using window.showmodal in js

I have created different folders for js, html, jsp, images, css etc in WebContent and i am using websphere 5.1.

Any help and clarification is appreciated.

Thanks and regards,
Karan
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Karan Jain:

But I am getting error because its trying to pass "/actualContextPathName".


I'm not sure what you mean by that exactly.

In JSP 2.0 a link, relative to the contextPath, would be built this way:


In JSP 1.2:



Does that help?
 
Sheriff
Posts: 67747
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
And be aware that you can never "pass" info from JSP to JavaScript. JSP is evaluated on the server, JavaScript on the client.
 
Karan Jain
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,
Thanks for the reply.


But I am getting error because its trying to pass "/actualContextPathName"



I mean to say that i am trying to pass the context path to the js function and as there is a forward slash "/" it might be giving the problem. I want to use the context path in the js function to open a jsp page.

If you see my code, i am using request.getContextPath() only.

But my confusion is still there because i thought that we can use the context path with any resource we are including but it does not seem like that.

If you see the code above in my previous post, I needed to include jsp in a different way than html and so forth.
I understanding was from wherever I am calling/including the resource contextpath should still work.

So in my code I should able to use:
/Contextpath/jsp/test.jsp
/Contextpath/html/test.html
/Contextpath/css/test.css etc.

It would be great if you can explain it further.

Thanks Bear for letting me know about that jsp, js stuff.

Actually I am very new to all these stuff.

Thanks and regards,
Karan
 
Bear Bibeault
Sheriff
Posts: 67747
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
I'm not sure exactly what your confusion is, but yes, for all client-initiated requests (images, css, JS files, etc) it is apporpriate for the URLs to all start with the context path.

The context path maps to the root of the web application (the folder that holds WEB-INF).

So if your images are in a folder named images at the same level as WEB-INF:

/contextpath/images/image.gif

will address an image in that folder.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Bear mentioned.
JSP and Javascript exist in two different worlds.
The easiest way to picture it (for me anyway) is to think "the JSP writes the Javascript"

So, if you want a Javascript variable named contextPath that contains the same value as the jsp's request.getContextPath(), you will need to write it.



If you look at the generated output from running this (View -> View HTML Source in your browser) you would see:
 
Bear Bibeault
Sheriff
Posts: 67747
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
This article may help with the JSP <--> JavaScript issue.
 
Karan Jain
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Bear and Ben...
Now I think my confusion is gone for most part and i implemented it and working fine... thanks a lot for you help and patience...

regards,
Karan
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic