Solved

searching for string within a string

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
handling Struts tag, JSTL tag and scriptlet in Ajax. 7 170
JSP Popup page 2 106
Set up Wildfly 10 8 358
Books that can get me started on JAVA 2 76
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

14 Experts available now in Live!

Get 1:1 Help Now