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

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

LVL 1
Shaye LarsenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

quincydudeCommented:

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"/>
0
Shaye LarsenAuthor Commented:
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

0
Shaye LarsenAuthor Commented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.