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!
however i can't figure out how to do simple string manipulation in JSP! (we are purely ASP / VBScript developers here)
thanks!
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.lastIn dexOf("/") + 1, path.lastIndexOf("."));
out.println(fileNameOnly);
%>
<%
String path = request.getServletPath();
String fileNameOnly = path.substring(path.lastIn
out.println(fileNameOnly);
%>
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?
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?
;-)
Look in your other question:
https://www.experts-exchange.com/questions/20790961/searching-for-string-within-a-string.html
Look in your other question:
https://www.experts-exchange.com/questions/20790961/searching-for-string-within-a-string.html
ASKER
ok, you've answered this question in my other question!
thanks :)
thanks :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.