Solved

Setting complete application file path

Posted on 2002-05-24
8
200 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 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to view directory list in apache/tomcat 9 116
spring AOP 6 86
servlet concurrency 13 102
null output 3 25
Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
Adding Computers to AD groups through an SCCM Task Sequence
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

778 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