春天3,瓷砖无法显示图像或使用CSS样式 [英] spring 3 , tiles can not display image or use css style

查看:88
本文介绍了春天3,瓷砖无法显示图像或使用CSS样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照一个教程部署了一个简单的spring 3应用程序.在那之后,我做了集成瓷砖2.现在,我正在尝试在瓷砖中使用css样式,但是我无法做到这一点,甚至无法显示图像.

I have deleloped a simple spring 3 application following a tutorial. After that, I did integrated tiles 2. Right now I am trying to use css style in my tiles but i can not do this and i can not even display an image.

在我的tile.xml里面,我有:

Inside my tiles.xml I have:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
   "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
   "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="base.definition"
    template="/WEB-INF/jsp/layout.jsp">
    <put-attribute name="title" value="" />
    <put-attribute name="header" value="/WEB-INF/jsp/header.jsp" />
    <put-attribute name="menu" value="/WEB-INF/jsp/menu.jsp" />
    <put-attribute name="body" value="" />
    <put-attribute name="styles" value="base.css"/>
    <put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" />
</definition>

<definition name="dogBreed" extends="base.definition">
    <put-attribute name="title" value="Contact Manager" />
    <put-attribute name="body" value="/WEB-INF/jsp/dogBreed.jsp" />
</definition>

</tiles-definitions>

我拥有的layout.jsp内部

Inside layout.jsp I have

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/styles/style.css"/>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<body>

<table border="1" cellspacing="0" cellpadding="0" style="width:100%;height:100%">
    <tr>
        <td height=10% width=100%><tiles:insertAttribute name="header" />
        </td>
    </tr>
    <tr>
        <td height=80% width=20%><tiles:insertAttribute name="menu" /></td>
        <td width=80%  height=80%><tiles:insertAttribute name="body" /></td>
    </tr>
    <tr>
        <td height=10% width=100%><tiles:insertAttribute name="footer" />
        </td>
    </tr>
</table>
</body>
</html>

我想要的是删除表结构并使用CSS.为此,我在layout.jsp上使用以下内容:

What I want is to remove the table structure and use css. For this I use on layout.jsp the following:

<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/style style.css"/>

现在我的header.jsp中有:

Now inside my header.jsp I have:

<div id="header">

   <div class="top_right">

        <div class="languages">
            <div class="lang_text">Languages:</div>
            <a href="#" class="lang"><img src="<%=request.getContextPath()%>/styles/images/en.gif" alt="" title="" border="0" /></a>
            <a href="#" class="lang"><img src="styles/images/de.gif" alt="" title="" border="0" /></a>       
        </div>

        <div class="big_banner">
        <a href="#"><img src="images/banner728.jpg" alt="" title="" border="0" /></a>
        </div>

    </div>


    <div id="logo">
        <a href="index.html"><img src="images/logo.png" alt="" title="" border="0" width="182" height="85" /></a>
    </div>
   </div>

这里没有图像显示,我不明白为什么.

None of the imaeges are getting displayed here and i do not understand why.

可用于显示css和图像的文件夹样式位于战争的rood文件夹中.

The folder styles which cotnrains css and images is in the rood folder of the war.

我在控制台中也收到一条错误消息,说在名为spring的调度程序servlet中找不到uri/pedsample/styles/images/en.gif的HTTP请求的映射"

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"

如果有任何帮助,我的web.xml包含以下内容:

My web.xml contains the following if od any help:

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

任何帮助将不胜感激.

非常感谢, 詹尼斯(Jiannis)

Thanks a lot, giannis

推荐答案

它与Tiles无关.

It's not related to Tiles.

由于DispatcherServlet被配置为处理应用程序中的所有URL,因此您需要对其进行配置以处理对静态内容的请求.

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

从Spring 3.0.4开始,可以通过将<mvc:resources>添加到您的Spring配置中来完成(也需要<mvc:annotation-driven />):

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/**" />

另请参见:

这篇关于春天3,瓷砖无法显示图像或使用CSS样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆