There is an error in your code : try to remove the ending '/' in file
'/template/index.jsp' line
<template:put attribute="site" direct="true"/>
---------------------------------^-- error
Also, you can have a look to Components/Extended Templates proposal : it provides
more features to deal
with templates / sub-templates.
Cedric
Components sites :
http://www.lifl.fr/~dumoulin/components/
(mirror) : http://www.geocities.com/cedricdumoulin/components/
Matthew Kennedy wrote:
> Hello, I'm just starting out with struts and I have run into a problem.
> I have a file 'index.jsp' which is a template. It inserts
> '/template/index.jsp' and puts the parameter 'site'.
>
> In turn, '/template/index.jsp' gets parameter 'site' and makes a put for
> the 'site' parameter of template called '/template/top_categories.jsp'
> which '/template/index.jsp' inserts.
>
> Hope that doesn't sound to confusing? Basically, I have the following:
>
> index.jsp (puts site='documentation')
> |
> V
> /template/index.jsp (gets site then puts site)
> |
> V
> /template/top_categories.jsp (gets site)
>
> I am trying to achieve the middle part with the following fragment from
> '/template/index.jsp' (see below for the full code).
>
> <template:insert template="/template/top_categories.jsp"/>
> <template:put name="site" direct="true"/>
> <template:get name="site"/>
> </template:put>
> </template:insert>
>
> Of course, this doesn't work (the exception encountered is below). So
> what technique do Struts users use to achieve this "templates within
> templates" implementation? Is it possible?
>
> Many thanks,
>
> Matthew
>
> ----/index.jsp----
> <%@ page contentType="text/html" %>
> <%@ taglib uri="/WEB-INF/tlds/struts/struts-template.tld"
> prefix="template" %>
> <template:insert template="/template/index.jsp">
> <template:put name="site" content="documentation" direct="true"/>
> </template:insert>
>
> ----/template/index.jsp----
> <%@ taglib uri="/WEB-INF/tlds/struts/struts-template.tld"
> prefix="template"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html lang="en">
> <head>
> <title>Site - <template:get name="site"/></title>
> </head>
> <body>
> <template:insert template="/template/top_categories.jsp"/>
> <template:put name="site" direct="true"/>
> <template:get name="site"/>
> </template:put>
> </template:insert>
> </body>
> </html>
>
> ----/template/top_categories.jsp----
> <%@taglib uri="/WEB-INF/tlds/dbtags/dbtags.tld" prefix="sql"%>
> <%@taglib uri="/WEB-INF/tlds/struts/struts-template.tld"
> prefix="template"%>
> <sql:connection id="conn">
> <sql:url>jdbc:postgresql://localhost/test</sql:url>
> <sql:driver>org.postgresql.Driver</sql:driver>
> <sql:userId>test</sql:userId>
> <sql:password/>
> </sql:connection>
> <h1 class="top_categories">Categories</h1>
> <table>
> <sql:statement id="stmt" conn="conn">
> <sql:query>
> SELECT id, title FROM category WHERE parent_id IS NULL
> </sql:query>
> <sql:resultSet id="rset">
> <tr>
> <td>
> <a href="<%= request.getContextPath()
> %>/index.jsp?site=<template:get name="site"/>&category=<sql:getColumn
> position="1"/>"><sql:getColumn position="2"/></a>
> </td>
> </td>
> </sql:resultSet>
> </sql:statement>
> </table>
> <sql:closeConnection conn="conn"/>
>
> ----500 error----
> Internal Servlet Error:
>
> javax.servlet.ServletException: PutTag.doEndTag(): No InsertTag ancestor
> at
>
>org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
> at
>
>_0002findex_0002ejspindex_jsp_19._jspService(_0002findex_0002ejspindex_jsp_19.java:127)
> at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
> org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
> at
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
> at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
> org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
> at org.apache.tomcat.core.Handler.service(Handler.java:286)
> at
> org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
> at
> org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
> at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
> at
>
>org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
> at
> org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
> at
> org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
> at java.lang.Thread.run(Thread.java:484)