View Full Version : [Q] c:import including code to be processed
betabagel
Apr 25th, 2006, 07:23 AM
I'm trying to include a page were the included page has some code like
<c: out value="Mambo jambo">
Only the code in the included page is never interpreted, it's ust written out plain as above. How could I make the "main" page interpret the including page as is done with the <%@ include file="somefile.jsp" %> :confused:
Colin Yates
Apr 25th, 2006, 07:54 AM
<jsp:include> will do just that.
Do make sure that the included file has all the required tag declarations it needs; it doesn't inherit them from the parent, neither does the standard prelude or coda.jsp get applied.
Colin Yates
Apr 25th, 2006, 07:56 AM
OK, I could be a bit more helpful :)
<jsp:include page="fragmentToBeIncluded.jspf"/>
and fragmentToBeIncluded.jspf
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c: out value="Mambo jambo">
betabagel
Apr 25th, 2006, 08:03 AM
Sorry, my bad...
Left out some information.
The actual import tag is a bit more complicated. It is combined with another variable like this:
<c:import url="${form}"/>
Hence I cannot use <jsp:include>...
jonmor
Apr 25th, 2006, 09:02 AM
What's the problem with using <jsp:include>? You can pass it a dynamically produced path in the page parameter and it will work fine.
Try this...
<c:set var="includedPage">mini.jsp</c:set>
<p><jsp:include page="${includedPage}"/></p>
...with this as mini.jsp:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:out value="${2*2}"/>
The correct answer will appear in your page as it should. (I'll leave working out the correct answer as an exercise for the reader).
Colin Yates
Apr 25th, 2006, 09:23 AM
Is it.... 4.672? :)
betabagel
Apr 25th, 2006, 09:44 AM
Then I must be doing something terribly wrong, cause 4 is not what I'm getting with the exact code. The result is closer to this:
The requested resource (/WEB-INF/views/jsp/${includedPage}) is not available
jonmor
Apr 25th, 2006, 10:10 AM
What servlet engine are you using? Does it understand JSP expression language? It would appear not, as it is not interpreting ${includedPage} at all.
betabagel
Apr 25th, 2006, 10:48 AM
I'm using Apache Tomcat/5.5.9, which I thought was a JSP 2.0 container with EL expressions. Hope I don't have to do some extra configuration to make it work?
After all I can retrive the variables like this:
<c: out variable="${includedPage}"/>
I've also doublechecked that I'm using jstl 1.1 and have standard.jar in my lib. Strange.
Colin Yates
Apr 25th, 2006, 10:57 AM
I'm using Apache Tomcat/5.5.9, which I thought was a JSP 2.0 container with EL expressions. Hope I don't have to do some extra configuration to make it work?
After all I can retrive the variables like this:
<c: out variable="${includedPage}"/>
I've also doublechecked that I'm using jstl 1.1 and have standard.jar in my lib. Strange.
What does your web.xml look like, in particular it needs the following schema definition:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
I would also remove any c.tld from your war.
betabagel
Apr 25th, 2006, 11:47 AM
That worked out just great! :)
Though I had to alter the taglib a little to this:
<%@ taglib prefix='c' uri='http://java.sun.com/jstl/core_rt' %>
I also saw some reference to adding <%@ page isELIgnored="false" %>
But it works well without it.
Guess I'll be crushed again tomorrow when I find out I cannot use the scope objects in the included page :rolleyes:
jonmor
Apr 25th, 2006, 11:51 AM
I'm using Apache Tomcat/5.5.9, which I thought was a JSP 2.0 container with EL expressions. Hope I don't have to do some extra configuration to make it work?
After all I can retrive the variables like this:
<c: out variable="${includedPage}"/>
That's because JSTL is handling the EL for you there - it doesn't require EL capability from the container. But your version of Tomcat should understand EL 'out of the box', unless something has disabled that. Definitely check the schema definition, as Yatesco suggests - if it is not for version 2.4, it should be. You could try putting the following line at the top of your problem page as a check:
<%@ page isELIgnored="false" %>
This will mean that EL will be interpreted for that page even if Tomcat is set not to for the whole application. (But do update the schema definition)!
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.