• Post Reply Bookmark Topic Watch Topic
  • New Topic

include directive with dynamic attribute file  RSS feed

 
JohanLof
Greenhorn
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
java.lang.Throwable(java.lang.String)
java.lang.Exception(java.lang.String)
javax.servlet.ServletException(java.lang.String)
org.apache.jasper.JasperException(java.lang.String)
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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66153
146
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.
hth,
bear
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!