0

I'm working with Tiles for the first time and I have problems with the integration with Spring 4. I'm trying to deploy the app to Tomcat server 8. I get "HTTP 404" when I try to access a jsp.

Here are my files:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>Spring-Hibernate</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>tiles</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>tiles</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

tiles-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd     
                    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 


    <mvc:annotation-driven/>
    <context:annotation-config />

    <context:component-scan  
        base-package="com.app.controller" />  

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

            </list>  
        </property>  
    </bean> 

    <bean id="dataSource" class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
            <property name="url" value="jdbc:mysql://localhost:3306/springdb"></property>
            <property name="password" value="passw"></property>
            <property name="username" value="root"></property>
            <property name="suppressClose" value="true"></property>
        </bean>

    <bean id="dataSourceProxy"
        class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy"
        p:targetDataSource-ref="dataSource" />


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
        p:dataSource-ref="dataSourceProxy" p:configLocation="classpath:/hibernate.cfg.xml" />


    <bean id="transactionManager"
        class="org.springframework.orm.hibernate5.HibernateTransactionManager"
        p:sessionFactory-ref="sessionFactory" />

</beans>

tiles.xml:

<definition name="base-template" template="/WEB-INF/template/template.jsp">
    <put-attribute name="title"   value="Spring MVC Tiles Integration" />
    <put-attribute name="content" value="" />
    <put-attribute name="header"  value="/WEB-INF/template/header.jsp" />
    <put-attribute name="footer"  value="/WEB-INF/template/footer.jsp" />
</definition>

<definition name="customers" extends="base-template">
    <put-attribute name="content" value="/WEB-INF/views/customers.jsp" />
</definition>

CustomerController

    @Controller
    public class CustomerController {

        @Autowired
        private CustomerService cService;

        @RequestMapping(value = "/customers", method = RequestMethod.GET)
        public ModelAndView getAllCustomers(Model model) {

            return new ModelAndView("customers", "customersList", cService.listCustomers());
        }
}

The tiles dependencies on my pom.xml:

<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-jsp</artifactId>
    <version>3.0.8</version>
</dependency>

<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-servlet</artifactId>
    <version>3.0.8</version>
</dependency>
<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-template</artifactId>
    <version>3.0.8</version>
</dependency>
<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-el</artifactId>
    <version>3.0.8</version>
</dependency>

And this is my error:

WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/application/customers] in DispatcherServlet with name 'tiles'

My WebContent folder looks like this

Jane C.
  • 55
  • 3
  • 13
  • If you use just `/customers` as a URL, does it work? I don't see where you set your application's context path to /application in the files above... – moilejter Aug 15 '18 at 19:47
  • /customers doesn't work. Before I start to use tiles, I used only springmvc and it worked ok with that url (/application/customers) because /application is the root. With tiles, I have a index jsp (that works ok) that has a href to /customers – Jane C. Aug 15 '18 at 20:02

1 Answers1

0

Your error makes me think that you might be putting in the wrong URL.

You're getting the 404 Error because you're calling a URL that you don't have a mapping for. Try just using /customers in your URL instead and see if that works.

John
  • 1
  • 3
  • I tried with /customers but doesn't work. My welcome file is index and works ok, and in that file I have a href to customers. Before I use tiles, this url (/application/customers) worked well with only springmvc. I don't understand the problem – Jane C. Aug 15 '18 at 20:00