title: Spring mvc with Tiles use .xhtml files instead of .jsp
body: <p>In my project I need to use tiles with spring and use .xhtml as my  view pages, but I cant make the project work whit.xhtml files, only with .jsp</p>
  
  <p>my tile.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE tiles-definitions PUBLIC
         "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
         "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"&gt;
  &lt;tiles-definitions&gt;
  
      &lt;definition name="base.definition" template="/WEB-INF/views/templates/layout.xhtml"&gt;
          &lt;put-attribute name="title" value="" /&gt;
          &lt;put-attribute name="header" value="/WEB-INF/views/templates/header.xhtml" /&gt;
          &lt;put-attribute name="menu" value="/WEB-INF/views/templates/menu.xhtml" /&gt;
          &lt;put-attribute name="body" value="" /&gt;
          &lt;put-attribute name="footer" value="/WEB-INF/views/templates/footer.xhtml" /&gt;
      &lt;/definition&gt;
  
      &lt;definition name="Contact" extends="base.definition"&gt;
          &lt;put-attribute name="title" value="Spring MVC - Contact Manager" /&gt;
          &lt;put-attribute name="body" value="/WEB-INF/views/contact.xhtml" /&gt;
      &lt;/definition&gt;
  
      &lt;definition name="/" extends="base.definition"&gt;
          &lt;put-attribute name="title" value="Spring MVC - Home" /&gt;
          &lt;put-attribute name="body" value="/WEB-INF/views/home.xhtml" /&gt;
      &lt;/definition&gt;
  
  &lt;/tiles-definitions&gt;
  </code></pre>
  
  <p>my servlet config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing 
          infrastructure --&gt;
  
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
      &lt;annotation-driven /&gt;
  
      &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving 
          up static resources in the ${webappRoot}/resources directory --&gt;
      &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
      &lt;!-- Tiles Configuration --&gt;
      &lt;beans:bean id="tilesConfigurer"
          class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;
          &lt;beans:property name="definitions" value="/WEB-INF/tiles.xml" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="viewResolver"
          class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
          &lt;beans:property name="viewClass"
              value="org.springframework.web.servlet.view.tiles2.TilesView" /&gt;
      &lt;/beans:bean&gt;
  
  &lt;!--    &lt;beans:bean id='viewResolver' class='org.springframework.web.servlet.view. --&gt;
  &lt;!--    InternalResourceViewResolver'&gt; --&gt;
  &lt;!--    &lt;beans:property name='prefix' value='/WEB-INF/'/&gt; --&gt;
  &lt;!--    &lt;beans:property name='suffix' value='.xhtml' /&gt; --&gt;
  &lt;!--    &lt;/beans:bean&gt; --&gt;
  
  
  
      &lt;!-- End Tiles Configuration --&gt;
  
      &lt;context:component-scan base-package="edu.youtube.tutorial" /&gt;
  
  
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>my web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" 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"&gt;
  
      &lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring/root-context.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;!-- Processes application requests --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>my template.xhtml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:tiles="http://tiles.apache.org/tags-tiles"&gt;
  &lt;h:head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
      &lt;title&gt;Estatistica&lt;/title&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;table border="1" cellpadding="2" cellspacing="2" align="center"&gt;
          &lt;tr&gt;
              &lt;td height="30" colspan="2"&gt;&lt;tiles:insertAttribute name="header" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td height="250"&gt;&lt;tiles:insertAttribute name="menu" /&gt;&lt;/td&gt;
              &lt;td width="350"&gt;&lt;tiles:insertAttribute name="body" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td height="30" colspan="2"&gt;&lt;tiles:insertAttribute name="footer" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and my footer.xhtml ( as a example)</p>
  
  <pre><code>work tork borrk test
  </code></pre>
  
  <p>my HomeController.java</p>
  
  <pre><code>package edu.youtube.tutorial.controller;
  
  import java.text.DateFormat;
  import java.util.Date;
  import java.util.Locale;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  /**
   * Handles requests for the application home page.
   */
  @Controller
  public class HomeController {
  
      private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
  
      /**
       * Simply selects the home view to render by returning its name.
       */
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public String home(Locale locale, Model model) {
          logger.info("Welcome home! The client locale is {}.", locale);
  
          Date date = new Date();
          DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
  
          String formattedDate = dateFormat.format(date);
  
          model.addAttribute("serverTime", formattedDate );
  
          return "/";
      }
  
  }
  </code></pre>
  
  <p>so, I found that viewresolver</p>
  
  <pre><code>&lt;!--    &lt;beans:bean id='viewResolver' class='org.springframework.web.servlet.view. --&gt;
  &lt;!--    InternalResourceViewResolver'&gt; --&gt;
  &lt;!--    &lt;beans:property name='prefix' value='/WEB-INF/'/&gt; --&gt;
  &lt;!--    &lt;beans:property name='suffix' value='.xhtml' /&gt; --&gt;
  &lt;!--    &lt;/beans:bean&gt; --&gt;
  </code></pre>
  
  <p>but didn't work</p>