Solved

Setting complete application file path

Posted on 2002-05-24
8
205 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
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 27

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
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!

 
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 27

Accepted Solution

by:
rrz earned 50 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 27

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This article outlines the struggles that Macs encounter in Windows-dominated workplace environments – and what Mac users can do to improve their network connectivity and remain productive.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

627 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