[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1698
  • Last Modified:

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?
0
cuttieveenz
Asked:
cuttieveenz
  • 2
1 Solution
 
rrzCommented:
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now