Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help: jsp include

 
Jo���o Ronaldo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a jsp file created to be a template. This template includes (by the jsp include tag) a file using an String variable called content. It follows:
<%@ include file=content%>
But when I run it, an error occurs:
org.apache.jasper.JasperException: /index.jsp(10,0) /window.jsp(23,22) quote symbol expected
Someone Knows how to solve it?
Thanks!
Joao
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
change the <%@ include file=content%>
code to:
<%@ include file=<%=content%> %> n it shall work..
 
Jo���o Ronaldo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nischal!
I already tried it too...
and the same error message occurs
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the file name has to be a string constant. Think about it: the actual include-ing is done before the JSP is translated into Java code, so obviously it happens long before the Java code is actually run. Therefore, you can't use "include" to compute different behaviors.
Depending on what you need to do, you might instead simply use an if-then statement with the contents of the different includes as the alternatives, or forward the incoming request to other JSPs based on the runtime requirements.
 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
<%@ include file="xyz.html" %> is called static inclusion. Here "xyz.html" can not be an expression. The following is invalid.
<% String content = "xyz.html"; %>
<%@ include file="<%= content %>" %> // invalid
You have to use the Dynamic inclusion
<jsp:include page="<%= content %>" /%> //valid
Thanks
Sainudheen
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And don't forget the quote characters.
<%@ include file="content.jsp"%>
bear
 
Jo���o Ronaldo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I tried to use <jsp:include page="<%= content %>"/%>
But I got another error messaged:
org.apache.jasper.JasperException: /index.jsp(14,0) /window.jsp(23,38) Unterminated
 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
If possible, try to run the file seperately which the string content is pointing to. Is that a JSP file?
----------------
Sainudheen
 
Sudhakar Reddy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there should not the % symbol in the <jsp:include...>
correcte one is
<jsp:include page="<%= content %>"/>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic