Is there a way in JSP to find out the name of the current page (not the whole URL or URI)? Of course, we can do something like the following to get the name of the current page in the JSP.
String servletPath=request.getServletPath(); out.println(servletPath.substring(servletPath.lastIndexOf("/")+1, servletPath.length()));
This can get the current page name (maybe I'm following the wrong way to do this). Is there a fair and direct way in JSP to get the name of the current page?
[In addition, the separator character /
in this method servletPath.lastIndexOf("/")
must always be independent of any file system supported by any operating system].
source share