spring 3 , tiles can not display image or use css style

梦想的初衷 提交于 2019-12-06 11:23:28

It's not related to Tiles.

Since DispatcherServlet is configured to handle all URL in your application, you need to configure it to handle requests for static content.

Since Spring 3.0.4 it can be done by adding <mvc:resources> to your Spring config (<mvc:annotation-driven /> is also needed):

<mvc:resources location="/styles/" mapping="/styles/**" />

See also:

It looks that your main problem is that the server is not able to provide your static content (images, css):

Also I get an error in my console saying that "no mapping found for HTTP request with uri /pedsample/styles/images/en.gif in dispatcher servlet with name spring"

What you need is a configured mapping for your static content in the spring configuration:

<!-- Handles HTTP GET requests for by efficiently serving up static resources -->
<mvc:resources location="/styles/" mapping="/styles/**"/>
<mvc:resources location="/images/" mapping="/images/**"/>

For more details: look at chapter "15.12.4 mvc:resources" of the spring reference

Added Of course you need to declare the mvc prefix:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd     
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
Andreas

Make sure you are using spring 3.0.4 or later otherwise the tag mvc:resources will not work, as it was introduced with that version according to the book "Spring in Action" book.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!