springMVC4.0.6 主题 <sprng:theme 和 静态资源 <mvc:reources 配置

首先, 首先, 的首先, 就是 主题 和静态资源的显示大多数是在JSP页面中显示(springMVC有多种视图),  

但是今天我学习的时候,犯了一个错, 就是不通过Controller, 直接访问 .jsp文件, 然后里面有 spring:theme标签就一直报错:

			javax.servlet.jsp.JspTagException: Theme 'theme': No message found under code 'theme.css' for locale 'zh_CN'.
     	而且直接访问.jsp文件, 在使用<mvc:resources 映射的静态资源时,只能使用图片文件, css和js文件是不能访问的
 
    so,  切记, 一定要经过Controller后定向到jsp,经过spring渲染,才能正常显示, 
		其中 forward:/xx.jsp  功能正常, 
	     	     redirect:/xx.jsp  和直接访问.jsp文件一样, 会报错,或不能访问
 
  言归正传, 直接看配置:
	文件结构:
	
	
    springMVC.xml:
 
	<!-- 专用拦截器 -->
	<mvc:interceptors>
		<!-- 主题改变拦截器  -->
		<bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"></bean>
		<!-- 本地化拦截器             依赖     localeResolver -->
		<bean class=" org.springframework.web.servlet.i18n.LocaleChangeInterceptor"></bean>
	</mvc:interceptors>
	
	<!-- 主题 -->
	<bean id="themeSource" class="org.springframework.ui.context.support.ResourceBundleThemeSource">
		<property name="basenamePrefix" value="conf.theme."/>
	</bean>
	<bean id="themeResolver"  class="org.springframework.web.servlet.theme.CookieThemeResolver">  
 		<property name="defaultThemeName" value="default"/>  
	</bean>
	
	<!-- 本地化-->
	<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
		<property name="cookieName" value="language"/>
		<property name="cookieMaxAge" value="3600"/>
		<property name="defaultLocale" value="zh_CN"/>
	</bean>	
	
	<mvc:resources location="/resource/theme/" mapping="/res/**"/>
 
    default.properties: 默认主题配置文件 
	theme.css=res/default/css/
	theme.img=res/default/img/
	theme.js=res/default/js/
   red.properties:
	theme.css=res/red/css/
	theme.img=res/red/img/
	theme.js=res/red/js/
 
  jsp中使用:
 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href='./<spring:theme code="theme.css"/>/main.css'>
<title>Insert title here</title>
</head>
<body>
	<h1>主题测试</h1>
	<img alt="" src="./<spring:theme code='theme.img'/>/logo.png">
</body>
</html>


	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值