Solved

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

Posted on 2002-03-14
6
188 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
Comment Utility
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
Comment Utility
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
Comment Utility
oops the line of code should read:
<jsp:include page="<%= varname %>" flush="true" />

CJ
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
kewl.  ...learn something new every day.
0
 
LVL 4

Author Comment

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

Expert Comment

by:cheekycj
Comment Utility
np.

Thanx for the "A".
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 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

10 Experts available now in Live!

Get 1:1 Help Now