Using the expression language ${...}
your variable must be accessible in one of the PageContext, Request, Session, Application...
scopes.
In order to make your code work, you must change it to:
<%
Foo foo=new Foo();
pageContext.setAttribute("foo", foo);
%>
<jsp:include page="${foo.getFileName()}"/>
If you are using a tag file, then prefer maybe jspContext
instead of pageContext
:
<%
Foo foo=new Foo();
jspContext.setAttribute("foo", foo);
%>
<jsp:include page="${foo.getFileName()}"/>