aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting a .jsp page Watch "Getting a .jsp page New topic
Author

Getting a .jsp page's name

Mike Firkser
Ranch Hand

Joined: Oct 21, 2003
Posts: 247

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
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting a .jsp page's name
 
Similar Threads
Sepration of Data from Presesntation layer
Searching within a file
can't able to write the actual format on a file
JSP - Problem in reading InitParameter
Load jsp into div tag of another jsp