Solved

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

Posted on 2002-03-14
6
195 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 50 total points
ID: 6867951
oops the line of code should read:
<jsp:include page="<%= varname %>" flush="true" />

CJ
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

688 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