2013-06-21 165 views
0

我配置了我的confugration文件ie。使用以下豆css文件在Spring主題模塊中不起作用。屬性文件加載正常,但CSS不起作用

<bean id="themeSource" class="org.springframework.ui.context.support.ResourceBundleThemeSource"> 
    <property name="basenamePrefix" value="theme-" /> 
</bean> 

<!-- Theme Change Interceptor and Resolver definition --> 
<bean id="themeChangeInterceptor" class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"> 
    <property name="paramName" value="theme" /> 
</bean> 
<bean id="themeResolver" class="org.springframework.web.servlet.theme.CookieThemeResolver"> 
    <property name="defaultThemeName" value="default" /> 
</bean> 

主題調度-servlet.xml文件我已經加入3個屬性的源目錄下 如theme-black.properties,theme-blue.properties,theme-default.properties。

每個屬性

文件,我添加鍵值對如下

style=style/blue.css 
style=style/black.css 
style=style/default.css 

我把風格文件夾下的Web內容。 問題是這個ResourceBundleThemeSource成功加載屬性文件,但無法加載css文件。

在JSP文件我已經添加follwing代碼

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

改變

<span style="float: right;"> <a href="?theme=default"> 
     default</a> &nbsp;| <a href="?theme=blue">blue</a> &nbsp;| <a 
    href="?theme=black">black</a> 
</span> 

請幫我如果有問題是有........請請請>謝謝提前

回答

0

我沒有Spring的主題支持經驗,但是我發現你的URL存在一個小錯誤。

首先你的網址是相對的。您應始終擁有絕對網址(從/開始)。

其次,使用任何URL時,你應該使用<c:url><spring:url>以便使用正確的上下文前綴:

<spring:url var="cssUrl"> 
    <jsp:attribute name="value"><spring:theme code="style"/></jsp:attribute> 
</spring:url> 
+0

嗨帕維爾,感謝您的快速回復,但我沒有得到你。我相信我的代碼中沒有使用任何網址。如果你知道可以請指導我。謝謝.... – pawan

+0

'href =「」' - 這裏你使用的是你的CSS文件的URL。你至少應該在你的屬性中添加前導斜槓'/'。通過URL標記處理它是可選的,取決於你的用例。如果CSS文件始終是最終WAR的一部分,則應該對其進行處理。如果它是外部參考或對另一個上下文的引用,則情況稍微複雜一些。 –

-1

我不知道你是否已經把豆themeChangeInterceptor裁判下豆DefaultAnnotationHandlerMapping。如果你這樣做,那麼請從那裏刪除,並把該<mvc:interceptors>標籤內像下面

<mvc:interceptors> 
<ref bean="themeChangeInterceptor" /> 
</mvc:interceptors> 
0

這是指定(在你application-config.xml)您的靜態內容的位置一樣簡單,從路徑其中訪問它們:

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

而接下來你編輯的主題性與文件: style=resources/style/blue.css

並把blue.css文件到:webapp/resources/themes

現在你可以使用加載css文件:

  1. "resources/themes/blue.css"href

  2. 還是在spring:theme標籤的使用codestyle

這對我有用。