[Last Call] Learn how to a build a cloud-first strategyRegister Now


How to change a java include file string with a java variable?

Posted on 2008-11-11
Medium Priority
Last Modified: 2013-11-23
How do you change the include file string with a Java variable?

For example:

<%@ include file="../flash_menus/menu_16.jsp" %> I want to make the number 16 dynamic, replace it with a variable. I don't understand the syntax to do it. Nothing has worked so far.

Here is my include file below and the variable I want to put in it.
<!-- Include file -->
<%@ include file="../flash_menus/menu_16.jsp" %>
<!-- Variable -->
<% ResponseBean.getTopBarMainID(0) %>

Open in new window

Question by:Shaye Larsen
  • 2
LVL 15

Assisted Solution

quincydude earned 2000 total points
ID: 22935940

Try :

<% String file="menu_";
      String path = "../flash_menus/";
      String location = path+file+"16.jsp";

<jsp:include page="<%=location%>" flush="true"/>

Reminded that per the JSP include sytanx you can use either the file-name in
quotes directly or you can give it as a variable within scriptlet tags but not as a combination of both like

<jsp:include page="../flash_menus/menu_<%=location%>.jsp" flush="true"/>

Author Comment

by:Shaye Larsen
ID: 22998148
Thank you very much. I utilized your code and it works great. However, I need to be able to dynamically change "16". SO I tried adding my databean there and when I do it won't show my include file.

Here is what I did to the code. Let me know how to correctly write this so I can change 16 also.

      String path = "../flash_menus/";
	  String file="menu_";
	  String ID = ResponseBean.getTopBarMainWidth(0);
      String location = path+file+ID+".jsp";
<jsp:include page="<%=location%>" flush="true"/>

Open in new window


Accepted Solution

Shaye Larsen earned 0 total points
ID: 23005833
Okay so the above code I displayed works. I just had a little error in my include file. Thank you for your help!

Here is the final solution thanks to the help of quincydude:
      String path = "../flash_menus/menu_";
	  String file= ResponseBean.getTopBarID(0);
	  String end =".jsp";
      String location = path+file+end;
<jsp:include page="<%=location%>" flush="true"/>

Open in new window


Featured Post

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!

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month18 days, 5 hours left to enroll

829 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