Getting Absolute path of a file on server using javascript

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?
cuttieveenzAsked:
Who is Participating?
 
rrzConnect With a Mentor Commented:
In JSP,  
<%
   String requestURL = request.getRequestURL().toString();
   String requestURI = request.getRequestURI();
   String serverURL = requestURL.substring(0,requestURL.indexOf(request.getRequestURI()));
%>
<%=serverURL%>
0
 
rrzCommented:
You could just use something like
  <script type='text/javascript' src='/yourFile.js'></script>  
Note the leading slash.
0
 
cuttieveenzAuthor Commented:
Hey Thanks... That worked for me!!! :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.