Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the current page name in JSP?

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].

like image 508
Tiny Avatar asked Jun 21 '12 02:06

Tiny


1 Answers

You can do it with URI method also.

String uri = request.getRequestURI();

String pageName = uri.substring(uri.lastIndexOf("/")+1);
like image 73
Rais Alam Avatar answered Oct 07 '22 12:10

Rais Alam