Solved

searching for string within a string

Posted on 2003-11-07
3
204 Views
Last Modified: 2010-04-01
following on from a previous question, i need to extract the folder and filename from request.getRequestURI()

ie "/folder/filename.jsp": string1 = "folder"; string2 = "filename"

and also i need to know if there is no folder (ie the file is in the root)

any thoughts?

0
Comment
Question by:equentin
  • 3
3 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9701290
Have a look at getPathInfo() and getPathTranslated() in HttpServletRequest.

AFAIK, getPathInfo() will return null if the file is in the root.
0
 
LVL 15

Accepted Solution

by:
jimmack earned 200 total points
ID: 9701563
Hmm.  They both seem to return null regardless (on my little test app).

However, you can get the folder using:

<%
String uriPath = request.getRequestURI();
String pathOnly = uriPath.substring(0, uriPath.lastIndexOf("/"));
out.println(pathOnly);
%>
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9701931
Thanks again ;-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

830 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