Solved

Getting Absolute path of a file on server using javascript

Posted on 2009-05-10
3
1,668 Views
Last Modified: 2012-06-27
Hi,
I am trying to include a '.js' file in my jsp. I am using its relative path. First time when the jsp is loaded the file is available. But the second time when the jsp is accessed, the relative path is not accessible. Can I use absolute path instead? Is there a way in javascript to get the absolute path of a file on server?
0
Comment
Question by:cuttieveenz
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
rrz earned 125 total points
ID: 24348487
In JSP,  
<%
   String requestURL = request.getRequestURL().toString();
   String requestURI = request.getRequestURI();
   String serverURL = requestURL.substring(0,requestURL.indexOf(request.getRequestURI()));
%>
<%=serverURL%>
0
 
LVL 27

Expert Comment

by:rrz
ID: 24348562
You could just use something like
  <script type='text/javascript' src='/yourFile.js'></script>  
Note the leading slash.
0
 

Author Closing Comment

by:cuttieveenz
ID: 31579912
Hey Thanks... That worked for me!!! :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now