By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

Access context path using javascript?

P: n/a
Hi,
I am running my website using Weblogic, so the path is something like
http://<myip>:<port>/<servername>/
On JSP pages I can use <%=request.getContextPath()%to get the root
path of the site, ie that specified above. How can I get the same using
Javascript?

For example, something like <a href='/home'>..</awill not work as
that would point to http://<myip>:<port>/home and needs to point to
http://<myip>:<port>/<servername>/home

Thank you in advance for any help,

D

Jul 11 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On JSP pages I can use <%=request.getContextPath()%to get the root
path of the site, ie that specified above. How can I get the same using
Javascript?
i dont think you can get context path directly in JS.
Instead define a global variable in JSP which will be initialized to
context path.
Now use this variable in js.

something like this.
Your JSP.

<script>
var contextPath = "<%=request.getContextPath()%>";
</script>
<script src="<%=request.getContextPath()%>/js/jsfile.js" />
Now you can use this variable in your jsfile.js.
Hope this helps you.

~Sunil

Jul 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.