Solved

searching for string within a string

Posted on 2003-11-07
3
200 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

16 Experts available now in Live!

Get 1:1 Help Now