Reputation: 27899
Is there a way in JSP to know the current page name (not the entire URL or URI)? Of course, we can do something like the following to retrieve the current page name in JSP.
String servletPath=request.getServletPath();
out.println(servletPath.substring(servletPath.lastIndexOf("/")+1, servletPath.length()));
This can retrieve the current page name (may be I'm following the wrong way to do so). Is there a fair and direct way in JSP to retrieve the current page name?
[Also, the separator character /
in this method servletPath.lastIndexOf("/")
should always be independent of any file system supported by any Operating System].
Upvotes: 9
Views: 26167
Reputation: 7016
You can do it with URI method also.
String uri = request.getRequestURI();
String pageName = uri.substring(uri.lastIndexOf("/")+1);
Upvotes: 25