Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

searching for string within a string

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
equentin
Asked:
equentin
  • 3
1 Solution
 
jimmackCommented:
Have a look at getPathInfo() and getPathTranslated() in HttpServletRequest.

AFAIK, getPathInfo() will return null if the file is in the root.
0
 
jimmackCommented:
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
 
jimmackCommented:
Thanks again ;-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now