0

我的应用程序正在运行,只是我的 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>

模板.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>

标准.css

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

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

}

标准属性

styleSheet=/resources/styles/standard.css

在此处输入图像描述

4

1 回答 1

0

试试这个:

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

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

<link rel="stylesheet" type="text/css" href="${csspath}" />
于 2013-05-06T19:32:14.873 回答