This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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 ]