Solved

Setting complete application file path

Posted on 2002-05-24
8
194 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
Comment Utility
Try this in a JSP    
 
<%=application.getRealPath(request.getServletPath())%>
0
 

Author Comment

by:Delphine_victorus
Comment Utility
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
Comment Utility
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
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
you can strip off the filename using string manipulations.

String fullPath = application.getRealPath(request.getServletPath());
String neededPath = fullPath.substring(0, fullPath.lastIndexOf("\"));
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 27

Accepted Solution

by:
rrz earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now