0

I wanted to know if I can pass a java variable to a . I tried to do something like this inside a jsp file:

<% String folder = request.getParameter("something"); %>
<jsp:include page="../<%=folder%>/myframe.jsp" ></jsp:include>

This does not work. I get an error which says 'Failed to find resource /=folder/myframe.jsp'. Can this be done?

Thanks for any help.

rgamber
  • 5,749
  • 10
  • 55
  • 99
  • Looks like it can't be done. However, you can [send parameters](http://java.sun.com/products/jsp/tags/11/syntaxref1112.html) to an included page. – adarshr Aug 31 '11 at 15:47
  • Yes, that way is straight forward. However I wanted to do it the above mentioned way. Thanks though! – rgamber Sep 09 '11 at 18:38

2 Answers2

0

Concidering your param name as "something", Try this:

<jsp:include page="../${param.something}/myframe.jsp" />

Other solution is to do that:

<% String folder = request.getParameter("something"); %>
<% pageContext.setAttribute("folder", folder); %>

<jsp:include page="../${folder}/myframe.jsp"></jsp:include>

First is better but both should works.

Dekx
  • 402
  • 2
  • 15
0

You either need to have the page parameter as an entire string or as an entire substitution.

<jsp:include page="<%= myPageToInclude %>" />
<jsp:include page="path/to/my/page.jsp" />

Also when concatenating strings inside a value you need to escape the double quotes. So for your problem :

<% String folder = request.getParameter("something"); %>
<jsp:include page="<%= \"../\" + folder + \"/myframe.jsp\" %>" />

Should work fine, or for easier reading :

<% 
    String folder = request.getParameter("something");
    String page = "../" + folder + "/myframe.jsp";
%>
<jsp:include page="<%= page %>" />
Ben
  • 532
  • 2
  • 4
  • 12