Solved

Setting complete application file path

Posted on 2002-05-24
8
201 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Display the newly inserted values 3 81
unit test DAO layer 1 139
dynamic reloading of jsp in jetty 2 121
instanceof  operator in java 26 95
Some of the SEO trends we might expect in 2017.
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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