?
Solved

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

Posted on 2002-03-14
6
Medium Priority
?
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 total points
ID: 6867951
oops the line of code should read:
<jsp:include page="<%= varname %>" flush="true" />

CJ
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

801 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