1

I want to create a simple JSP tiles 3.0 web application. I have a header,footer, menu and a body to load the jsps. My application works in tiles 2.2 but now I'm trying to convert it to tiles 3.0

I'm not allowed to use frameworks. I create the war using "MyAnt generate.war" and I deploy it with tomcat.

Here is my tiles definition file (tiles.xml)

    <!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">


<tiles-definitions>
  <definition name="page" template="/template.jsp">
    <put-attribute name="header" value="/defaultHeader.jsp" />
    <put-attribute name="menu" value="/defaultMenu.jsp" />
    <put-attribute name="body" value="/empty.jsp" />
    <put-attribute name="footer" value="/defaultFooter.jsp" />
  </definition>
  <definition name="servletPage" extends="page">
    <put-attribute name="body" value="/form.jsp" />
  </definition>

  <definition name="jspPage" extends="page">
    <put-attribute name="body" value="/hello.jsp" />
  </definition>
</tiles-definitions>

template.jsp

 <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<html>
  <body style="width:100%;height:100%" bgcolor="Blue">
    <table border="1" cellspacing="0" cellpadding="0" style="width:100%;height:100%">
      <tr> <td colspan="2"><tiles:insertAttribute name="header" /> </td> </tr>
      <tr> <td>  <tiles:insertAttribute name="menu" /> </td>
           <td>  <tiles:insertAttribute name="body" /> </td>  </tr>
      <tr> <td colspan="2"> <tiles:insertAttribute name="footer" /> </td> </tr>
    </table>
  </body>
</html>

index.jsp

 <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<tiles:insertDefinition name="page" />

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     version="2.5">
<servlet>
    <servlet-name>tiles</servlet-name>
    <servlet-class>org.apache.tiles.web.startup.TilesServlet</servlet-class>
    <init-param>
      <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
      <param-value>/WEB-INF/tiles.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

And this is the error that I've got in the browser

HTTP Status 500 - An exception occurred processing JSP page /index.jsp at line 2 
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 2

1: <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
2: <tiles:insertDefinition name="page" />

Can anyone please help me fix it? I'm pretty sure that the problem it's in web.xml, but I can't figure out what should I do.

D.Andreea
  • 41
  • 2
  • There is almost no difference between tiles2 and tiles3, tiles3 of course has an expansion of features... I don't know why you bring up not being able to use web frameworks, sounds like a silly requirement but does not have any bearing on the issue. Are you using maven? Might be missing a dependency... what reason do you have for not using "org.apache.tiles.extras.complete.CompleteAutoloadTilesListener" in web.xml? – Quaternion Jun 13 '13 at 20:56
  • What is index.jsp trying to do? tiles:insertDefinition is for creating a new definition¹, but you have already defined the "page" definition in your tiles.xml ¹ http://tiles.apache.org/framework/tiles-jsp/tagreference.html#tiles:insertDefinition – mck Jun 18 '13 at 09:16
  • `I'm not allowed to use frameworks` -- You realize Tiles itself is a framework right? `I create the war using "MyAnt generate.war"` -- This is just the name of the task in your build script, meaningless for anyone else. – Dave L. Jul 22 '13 at 19:06

1 Answers1

0

With Struts, the class is: org.apache.tiles.web.startup.TilesServlet Without Struts the class is : org.apache.struts.tiles.TilesServlet

halfelf
  • 9,737
  • 13
  • 54
  • 63