Spring MVC Theming,CSS不适用

时间:2013-05-06 18:39:54

标签: spring-mvc theming

我的应用程序正在运行,但我的CSS文件不是。我正在使用Spring MVC和主题。也许有人可以查看我的代码,看看我做错了什么。我还包括了我的项目目录的截图。当我查看应用程序的页面源时,链接rel标记中“href”链接的末尾附加了一个jSessionId。那会有什么影响吗?

servlet的context.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    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">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**"/>

    <default-servlet-handler/>

    <!-- Tiles Configuration -->
    <beans:bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="tilesViewResolver">
        <beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
    </beans:bean>

    <beans:bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" id="tilesConfigurer">
        <beans:property name="definitions">
            <beans:list>
                <beans:value>/WEB-INF/layouts/tiles.xml</beans:value>
            </beans:list>
        </beans:property>
    </beans:bean>


    <interceptors>
        <beans:bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/>
        <beans:bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang"/> 
    </interceptors>

    <beans:bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource" p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application" p:fallbackToSystemLocale="false"/>

    <beans:bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver" id="localeResolver" p:cookieName="locale"/>


    <context:component-scan base-package="com.jamesanthony527.herdmanager.controller" />
<beans:bean class="org.springframework.ui.context.support.ResourceBundleThemeSource" id="themeSource"/>
<beans:bean class="org.springframework.web.servlet.theme.CookieThemeResolver" id="themeResolver" p:cookieName="theme" p:defaultThemeName="standard"/>   


</beans:beans>

template.jsp

<!DOCTYPE HTML>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>


<spring:message code="welcome_titlebar" var="TitleBar"/>

<html>
    <head>
        <!-- <meta charset="utf-8"> -->

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />



        <link rel="stylesheet" type="text/css" href="<spring:theme code="styleSheet" />" />


        <title>${TitleBar}</title>
    </head>

    <body>
        <div id="wrapper">
            <div id="header"><tiles:insertAttribute name="header"/></div>
            <div id="body"><tiles:insertAttribute name="body"/></div>
            <div id="footer"><tiles:insertAttribute name="footer"/></div>
        </div> <!-- end wrapper -->
    </body>
</html>

standard.css

#wrapper {
    height:800px;
    width:600px;
    background-color: #00FFFF;
}

#head {
    height:100px;
    width:100px;

}

standard.properties

styleSheet=/resources/styles/standard.css

enter image description here

1 个答案:

答案 0 :(得分:0)

请改为尝试:

<spring:theme var="cssresource" code="styleSheet" />

<spring:url var="csspath" url="${cssresource} />

<link rel="stylesheet" type="text/css" href="${csspath}" />