Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting complete application file path

Posted on 2002-05-24
8
Medium Priority
?
209 Views
Last Modified: 2010-04-01
Is there any method to get the complete application file path(c:\Apache\webapps\index.jsp) using Servlet and jsp

Here I should get the path upto c:\Apache\webapps from the method

oris there any other way

please help
0
Comment
Question by:Delphine_victorus
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 28

Expert Comment

by:rrz
ID: 7033237
Try this in a JSP    
 
<%=application.getRealPath(request.getServletPath())%>
0
 

Author Comment

by:Delphine_victorus
ID: 7033303
thanks for reply

this code gives me the complete application file path

I would like to have a method which can get me the portion of the path ,for instance C:\Apache\webapps\myapp\new of the complete app path which may look like C:\Apache\webapps\myapp\new\index.jdp
0
 

Author Comment

by:Delphine_victorus
ID: 7033326
thanks for reply

this code gives me the complete application file path

I would like to have a method which can get me the portion of the path ,for instance C:\Apache\webapps\myapp\new of the complete app path which may look like C:\Apache\webapps\myapp\new\index.jdp
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 19

Expert Comment

by:cheekycj
ID: 7034345
you can strip off the filename using string manipulations.

String fullPath = application.getRealPath(request.getServletPath());
String neededPath = fullPath.substring(0, fullPath.lastIndexOf("\"));
0
 
LVL 28

Accepted Solution

by:
rrz earned 200 total points
ID: 7034402
Or another way, for system independence,  
<%
  java.io.File file = new java.io.File(application.getRealPath(request.getServletPath()));  
%>
Path to parent is  <%=file.getParent()%>
0
 
LVL 92

Expert Comment

by:objects
ID: 7034874
Try something like this:

<%

String path = application.getRealPath(request.getServletPath());
String uri = request.getRequestURI();

String desired = path.substring(0, path.length()-uri.length());

%>
0
 
LVL 28

Expert Comment

by:rrz
ID: 7034893
I am confused I thought "Delphine" wanted the parent directory.  
"objects" your code in  Tomcat results in  
desired= Tomcat_Home\webapps
0
 
LVL 92

Expert Comment

by:objects
ID: 7036216
I thought they wanted the root directory of the webapp, though I'll have to admit I'm not positive.
My codes wrong anyway, should be something like:

<%

String path = application.getRealPath(request.getServletPath());
String uri = request.getRequestURI();
String ctx = request.getContextPath();
String desired = path.substring(0,
  path.length() - uri.length() + ctx.length());

%>
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

885 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