如何配置CSS与Spring MVC和tile

时间:2023-01-12 23:31:11

I'm using Spring 3.0.5 and Tiles 2.2.2 and I can't manage to get a stylesheet properly referenced in my app.

我使用的是Spring 3.0.5和Tiles 2.2.2,无法在应用程序中正确引用样式表。

My stylesheet is in:

我的样式表:

WEB-INF/static/css/styles.css

web - inf /静态/ css / styles。css

How do I declare it properly in my main Tiles JSP? I've been trying to figure this out for a couple of days now, and I've tried a number of suggestions that I've seen here and in other sites. I've tried adding

如何在我的主Tiles JSP中正确地声明它?我花了几天的时间来研究这个问题,我尝试了一些我在这里和其他网站上看到的建议。我试着添加

<mvc:resources ...>

to my spring config, although not all suggested solutions include this. No doubt it's very simple, but I just haven't found something that works.

对于我的spring配置,尽管不是所有建议的解决方案都包含这个。毫无疑问,这很简单,但我还没有找到有效的方法。

Any help is very much appreciated!

非常感谢您的帮助!

1 个解决方案

#1


6  

Hi Jazz i used to put the css files outside web-inf with the following configuration using spring mvc and some jstl but this configuration i guess is generic so i hope this "should help you" :

嗨,Jazz,我曾经将css文件放在web-inf之外,使用spring mvc和一些jstl进行如下配置,但是我想这个配置是通用的,所以我希望这个“应该对您有所帮助”:

In the web.xml i add :

在web。xml添加:

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>

And in the page header i reference to css file with the following code :

在页面标题中,我引用css文件的代码如下:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<head>
    <title></title>
    <link href="${pageContext.request.contextPath}/css/global.css" rel="stylesheet" type="text/css" />
</head>

Regards..

问候. .

#1


6  

Hi Jazz i used to put the css files outside web-inf with the following configuration using spring mvc and some jstl but this configuration i guess is generic so i hope this "should help you" :

嗨,Jazz,我曾经将css文件放在web-inf之外,使用spring mvc和一些jstl进行如下配置,但是我想这个配置是通用的,所以我希望这个“应该对您有所帮助”:

In the web.xml i add :

在web。xml添加:

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>

And in the page header i reference to css file with the following code :

在页面标题中,我引用css文件的代码如下:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<head>
    <title></title>
    <link href="${pageContext.request.contextPath}/css/global.css" rel="stylesheet" type="text/css" />
</head>

Regards..

问候. .