Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the JSP page name

 
Miguel Saenz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the getRequestURI method of the request object.
i.e request.getRequestURI(), which returns a string (this includes the path information also).
 
Miguel Saenz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic