Link to home
Start Free TrialLog in
Avatar of daluu
daluuFlag for United States of America

asked on

Including files using variables/data types instead of a filename string value

Hi, I'm working on a website template, converting PHP code to JSP code. But I've come across a problem with including files using variables/data types instead of a filename string value.

With PHP that would look like this:
<?php $var = "filename"; ?>
/* and then later on below: */
<?php include($var); ?>

But a JSP equivalent of:
<% String var = "filename"; %>
/* and then later below: */
<%@ include file = var %>

doesn't work because the value must be in quotes unlike PHP. Is there a work around? Or do I have no choice in using variables/data types in this kind of situation?
Avatar of knightEknight
knightEknight
Flag of United States of America image

I don't know anything about PHP ... if it uses PERL or some other runtime scripting language, then there are things you can do with it that you will not be able to do with Java in JSP because the Java classes are compiled to (virtual) executables (class files) before runtime.  I don't know that much about JSP either, but I know you can't import a file that way in Java, so I doubt you can include one that way in JSP.
you can use vars in dynamic includes:
<jsp:include page<%= varname %>" flush="true" />

Static includes directives are preprocessed before scripting code executes so you cannot use variables there.

CJ
ASKER CERTIFIED SOLUTION
Avatar of cheekycj
cheekycj
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
kewl.  ...learn something new every day.
Avatar of daluu

ASKER

thanks for the code, CJ. I actually overlooked that command.
np.

Thanx for the "A".