Solved

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

Posted on 2002-03-14
6
190 Views
Last Modified: 2013-11-18
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?
0
Comment
Question by:daluu
  • 3
  • 2
6 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 6867713
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.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6867945
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
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 50 total points
ID: 6867951
oops the line of code should read:
<jsp:include page="<%= varname %>" flush="true" />

CJ
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Expert Comment

by:knightEknight
ID: 6868005
kewl.  ...learn something new every day.
0
 
LVL 4

Author Comment

by:daluu
ID: 6869261
thanks for the code, CJ. I actually overlooked that command.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6869265
np.

Thanx for the "A".
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Web Application Architecture 6 75
spring example errors 33 259
maven webservice example issue 2 122
How to write an English digest paper 6 24
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now