File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Getting a .jsp page's name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting a .jsp page Watch "Getting a .jsp page New topic

Getting a .jsp page's name

Mike Firkser
Ranch Hand

Joined: Oct 21, 2003
Posts: 248

I've tried getting the answer from the doco for page and pageContext, to no avail. Is there a way to get the name of the page/.jsp file.

What I want to do is create an include file, and have it show different images based on the page that is being displayed. I can pass the page name as a parameter, but I'd like to know if there is a way to do this through jsp's implicit objects?

Thanks in advance.

Mike Firkser
Rutgers '84
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

No, there is no way. And it would really be not a very good way to do it if you could.

Doing so would rely on implicit/environmental data that could easily change. It's a far better approach to be explicit about passing in data that triggers the change in behavior. In fact, even when explicitly passed, I wouldn't use the parent filename as the trigger, but something that was a clear abstraction of the situation that is causing the difference.

Let's say for example, in the include file you want to include or not include an image. Rather than saying "if my parent is 'a', show it, but if my parent is 'b', don't", I would set a request attribute named something like "showImage". Parent 'a' would set it to true, and parent 'b' to false (or omit it, construed to mean false).

This way you have decoupled the conditional from its environment. So if now you add more parents, change the parent's names, and so forth, you have insulated yourself from breaking things just because the environment changed.
[ May 19, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Getting a .jsp page's name
It's not a secret anymore!