It's not a secret anymore!*
The moose likes JSP and the fly likes How to get the JSP page name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "How to get the JSP page name" Watch "How to get the JSP page name" New topic
Author

How to get the JSP page name

Miguel Saenz
Greenhorn

Joined: Jul 16, 2002
Posts: 4
Hello all,
Does any one know how to get/print the current JSP page name? PHP has a $PHP_SELF that holds the file name. Is there an equivalent for $PHP_SELF in JSP?
Thank you in advance for your time and help.
Mike
Joshi Thomas
Greenhorn

Joined: Oct 03, 2002
Posts: 7
use the getRequestURI method of the request object.
i.e request.getRequestURI(), which returns a string (this includes the path information also).


SCJP<br />SCWCD
Miguel Saenz
Greenhorn

Joined: Jul 16, 2002
Posts: 4
The request.getRequestURI() method doesn't work for the following scenario:
When including menu.jsp into my index.jsp page (<jsp:include page="menu.jsp" /> , the first line in menu.jsp is something like:

to show that I am including menu.jsp in my index.jsp page but it doesn't print menu.jsp, it prints index.jsp.
Does any one know how to get the "Begin include of menu.jsp" to be printed out in index.jsp instead of "Begin include of index.jsp"?
Thanks
Joshi Thomas
Greenhorn

Joined: Oct 03, 2002
Posts: 7
One more thing you can do is store "menu.jsp" in a variable in menu.jsp and use that variable in your index.jsp.
In menu.jsp
String pagename = "menu.jsp";
In index.jsp
<include menu.jsp>
Begining include of <%=pagename %>
Miguel Saenz
Greenhorn

Joined: Jul 16, 2002
Posts: 4
Hello all,
I found the answer to my question!
The answer is:

This represents the name of the jsp file.
Or the following will also work:

Hope this helps someone else.
Thank you
-Mike
Miguel Saenz
Greenhorn

Joined: Jul 16, 2002
Posts: 4
If the previous answer seemed too long, try this:

To be honest I don't know exactly what's the difference but it works.
Thanks
-Mike
 
GeeCON Prague 2014
 
subject: How to get the JSP page name