July 16th, 2002, 04:32 AM
Hello, I have a quick question... does JSP have something similar to Coldfusions Application.cfm file? I would like to run some code (say application.jsp) before any of the other files are accessed....
I know I can include application.jsp in every file, but I would prefer not to. Thanks.
July 16th, 2002, 09:50 PM
! got another question.... is there any way to include a file using a variable in the include statemen (example below):
String filename = test.jsp;
<%@ include file= filename %>
July 17th, 2002, 10:13 AM
I think you have the two include methods mixed up. The one you've used above is a static include. It only happens on the first compile. It can't be dynamic because it happens before code is run or even generated.
The method you would use to dynamically include another file is <jsp:include page="test.jsp" flush="true" />. If you want to use a variable you can do it like this:
<% String filename = "test.jsp"; %>
<jsp:include page="<%=filename %>" flush="true" />
you can also send parameters to the included file like this:
<jsp:include page="test.jsp" flush="true">
<jsp:param name="parametername" value="parametervalue" />
The param value can be a variable using the <%=variable %> syntax as well