File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Custom tags to override jsp include action and @include directive 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 "Custom tags to override jsp include action and @include directive" Watch "Custom tags to override jsp include action and @include directive" New topic

Custom tags to override jsp include action and @include directive

sandeeprajsingh tandon
Ranch Hand

Joined: Mar 06, 2009
Posts: 70
I think its a little strange requirement but
i have a 1000 jsp files that use jsp:include and @include for including other jsps.
Now, i want to make it possible for these functionalities to have dynamic jsp paths.
i.e jsp:include path="<%=DynamicPath%>/test.jsp", where DynamicPath will be available only at request time. This it seems is not possible as per the documentation of jsp:include
It would be too much work to go into 1000 files, change the path attribute to point to an expression and declare that expression in the jsp.

I thought i could create a custom tag for Myjsp:include where i could add path to the page attribute in my tag and then call the jsp:include from with in that.

Could anyone provide me a pointer on that?.

Stefan Evans

Joined: Jul 06, 2005
Posts: 1016
Possible for <jsp:include> tags.
Not possible for @Include directive which is resolved at compile time.

Consider using an EL expression such as ${dynamicPath} rather than a scriptlet expression.
I would try to stick with the <jsp:include> rather than customising it. Global search and replace refactoring tools should do a pretty good job in this case - provided its a relatively simple change.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60050

This is not a run-time problem. If the editing tools you are using make it hard to make these sorts of changes across multiple files, you need better tools, not a custom tag.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Custom tags to override jsp include action and @include directive
Similar Threads
include action vs. include directive
Relative URL specifications, JSP 1.2.1
Dynamic include in custom tag body
Including a file dynamically
Using Custom tags inside HTML or Scriptlet