[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Getting Absolute path of a file on server using javascript

Posted on 2009-05-10
3
Medium Priority
?
1,692 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 28

Accepted Solution

by:
rrz earned 500 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 28

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

With the evolution of technology, we have finally reached a point where it is possible to have home automation features like having your thermostat turn up and door lock itself when you leave, as well as a complete home security system. This is a st…
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 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