File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Please help: jsp include Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Please help: jsp include" Watch "Please help: jsp include" New topic

Please help: jsp include

Jo���o Ronaldo

Joined: Sep 24, 2003
Posts: 6
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?
Nischal Tanna
Ranch Hand

Joined: Aug 19, 2003
Posts: 182
change the <%@ include file=content%>
code to:
<%@ include file=<%=content%> %> n it shall work..

Jo���o Ronaldo

Joined: Sep 24, 2003
Posts: 6
Hi Nischal!
I already tried it too...
and the same error message occurs
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

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.

[Jess in Action][AskingGoodQuestions]
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
<%@ 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
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63540

And don't forget the quote characters.
<%@ include file="content.jsp"%>

[Asking smart questions] [About Bear] [Books by Bear]
Jo���o Ronaldo

Joined: Sep 24, 2003
Posts: 6
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

Joined: Aug 18, 2003
Posts: 218
If possible, try to run the file seperately which the string content is pointing to. Is that a JSP file?
Sudhakar Reddy

Joined: Aug 28, 2003
Posts: 9
there should not the % symbol in the <jsp:include...>
correcte one is
<jsp:include page="<%= content %>"/>
I agree. Here's the link:
subject: Please help: jsp include
jQuery in Action, 3rd edition