Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

include directive with dynamic attribute file  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, currently I'm wrestling with the following problem. I want to include a certain file in a JSP and I'm receiving the filename to be included from the request as a parameter.
This is my code so far.
<%-- Include dynamical path settings --%>
<% java.lang.String envJsp=request.getParameter("envJsp");%>
<%@ include file="<%=envJsp%>" %>
<%-- End Include dynamical path settings --%>
This results in the following error:
org.apache.jasper.JasperException: Bad file argument to include
void org.apache.jasper.compiler.JspParseEventListener.handleDirective(java.lang.String, org.apache.jasper.compiler.Mark, org.apache.jasper.compiler.Mark, java.util.Hashtable)
void org.apache.jasper.compiler.DelegatingListener.handleDirective(java.lang.String, org.apache.jasper.compiler.Mark, org.apache.jasper.compiler.Mark, java.util.Hashtable)
boolean org.apache.jasper.compiler.Parser$Directive.accept(org.apache.jasper.compiler.ParseEventListener, org.apache.jasper.compiler.JspReader, org.apache.jasper.compiler.Parser)
void org.apache.jasper.compiler.Parser.parse(java.lang.String, java.lang.Class [])
void org.apache.jasper.compiler.Parser.parse(java.lang.String)
void org.apache.jasper.compiler.Parser.parse()
boolean org.apache.jasper.compiler.Compiler.compile()
Has anyone experience with this, or isnt it possible ate all perhaps???
All suggestions are more than welcom.
Greeetins, Johan
Author and ninkuma
Posts: 66685
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not possible with the include directive. The directive gets evalauted when the servlet for the JSP is being constructed -- long before the Java code on the page gets executed.
You can use a variable path with the <jsp:include/> tag, which gets evaluated at run time.
Something about .... going for a swim. With this tiny ad ...
free 1 hour java lesson
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!