Search code examples
javaspring-mvcapache-tiles

Spring MVC: Apache Tile don´t work


I am doing a web app with spring mvc and apache tiles and i have the next:

Project

|__WebContent

|__WEB-INF

 |___ spring
   |__app-config.xml

 |___ views
   |__footer.jsp
   |__header.jsp
   |__home.jsp
   |__layout.jsp
   |__menu.jsp

 |___ tiles.xml
 |___ web.xml

|__index.jsp

In app-config.xml:

<bean id="viewResolver"
 class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>

My layout.jsp:

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<body>
<div><tiles:insertAttribute name="header" /></div>
<div style="float:left;padding:10px;width:15%;"><tiles:insertAttribute
name="menu" /></div>
<div style="float:left;padding:10px;width:80%;border-left:1px solid pink;">
<tiles:insertAttribute name="body" /></div>
<div style="clear:both"><tiles:insertAttribute name="footer" /></div>
</body>
</html>

My tiles.xml:

<tiles-definitions>
<definition name="base.definition"  template="/WEB-INF/view/layout.jsp">
<put-attribute name="title"     value="" />
<put-attribute name="header"    value="/WEB-INF/view/header.jsp" />
<put-attribute name="menu"      value="/WEB-INF/view/menu.jsp" />
<put-attribute name="body"      value="" />
<put-attribute name="footer"    value="/WEB-INF/view/footer.jsp" />
</definition>
<definition name="home" extends="base.definition">
<put-attribute name="title" value="Home" />
<put-attribute name="body"  value="/WEB-INF/view/home.jsp" />
</definition>
</tiles-definitions>

And my controller:

@Controller
public class HomeController {

@RequestMapping(value="/home")
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
return new ModelAndView("home");
}

It gives me the error when i enter to http://localhost:8080/unqui.tip.vista/home.html:

http 404 /unqui.tip.vista/WEB-INF/view/layout.jsp

Ty.


Solution

  • This may be a typo from when you wrote it, but your value for the body in your tiles.xml should be this:

    <put-attribute name="body"  value="/WEB-INF/views/home.jsp" />
    

    Since your home.jsp is in the views folder, you need the s on the end. You'll need to update all of the tiles.xml paths to say views.