Link to home
Start Free TrialLog in
Avatar of equentin
equentin

asked on

JSP - how to get filename only from the HTTP header

hi, i need to extract the filename only from the HTTP header (getRequestURI?) excluding the ".jsp". so if "folder/file.jsp" was the path i need "file" as a variable. this is so i know what page the user is on for setting up menu selected states, etc.

however i can't figure out how to do simple string manipulation in JSP!  (we are purely ASP / VBScript developers here)

thanks!
Avatar of jimmack
jimmack

getServletPath() will tell you the part of the URL that called the servlet.
From within a JSP, you can do the following:

<%
String path = request.getServletPath();
String fileNameOnly = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
out.println(fileNameOnly);
%>

Avatar of equentin

ASKER

cool, thanks, but how about a potential folder name?

i suppose i could get the lastIndexOf "/" then backtrack from there to find the next "/" then pull out whatever is in between, or if not found then there is no folder.

any better ideas?

ok, you've answered this question in my other question!

thanks :)
ASKER CERTIFIED SOLUTION
Avatar of jimmack
jimmack

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial