Forums Register Login

Dynamic include file question

+Pie Number of slices to send: Send
I need to use dynamically generated file names in my <%@ include file="" %> directive.
I am using objects (such as database connection) in the included files which I created in my base JSP file. For this reason, I cannot use the jsp:include tag (since these objects are not defined in these files, the servlet doesn't compile).
Are there any ways of using these dynamic file names in this directive?
+Pie Number of slices to send: Send
Store the objects in request-scope properties, and use <jsp:include>.
[ August 22, 2003: Message edited by: Ron Newman ]
+Pie Number of slices to send: Send
Hi Ulvi,
The issue here is to do with how the jsp:include and <%@ include file="" %> work. The former includes the file at request time therefore it has the specific variables and you can pass dynamic filenames. The latter is included at the translation times, thus it is not even aware of what the values are going to be so you can not include dynamic file names. There is a very nice explanation of this in SCWCD Study Kit.
As for being able to share the resources, there are better ways to achieve that such as placing the objects in request scope, session scope or application scope depending on the nature of the object and what you want to do with them.
IHTH
- FK
+Pie Number of slices to send: Send
Can you suggest a way to pass the database connection object to the file using <jsp:include> tag? Thanks.
+Pie Number of slices to send: Send
Faisal gave you the clues. If the objects follow the bean pattern, you can place them in request scope on the parent page and use <jsp:useBean> to pick them up in the included pages.
If they are not bean-patterned, the included pages can pick them up using request.getAttribute() (which is what useBean will do behind the scenes anyways).
hth,
bear
P.S. I won't go into my usual tirade about the pitfalls of performing database actions from JSP pages; that's an architecture issue you can find out lots about with a search.
[ August 22, 2003: Message edited by: Bear Bibeault ]
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1118 times.
Similar Threads
variables in included file
include directive doubt?
doubts realted to include directive
View all included JSP Source in one file
include directive
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:39:59.