Solved

Getting Absolute path of a file on server using javascript

Posted on 2009-05-10
3
1,676 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Display current date,month,and year to JTextField 3 63
tomcat users xml 7 136
best tutorial on log4j and logging for servlets/jsp codes 1 65
null output 3 42
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

740 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