springMVC + velocity

java.lang.ClassNotFoundException: org.springframework.web.servlet.view.velocity.VelocityConfigurer

 

這個問題加入 spring-context-support-3.2.2.RELEASE.jar 就OK了

 

velocity eclipse插件

https://code.google.com/p/veloeclipse/

 

<bean id="velocityConfig"
		class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"
		p:resourceLoaderPath="/WEB-INF/velocity/" />
<!-- 		p:configLocation="classpath:common/velocity.properties" /> -->

	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"
		p:suffix=".vm" />

 

 SpringMVC + velocity獲得requset session的問題

首先,要在 org.springframework.web.servlet.view.velocity.VelocityViewResolver 裏把

request/session 暴露出來:

 

p:exposeRequestAttributes="true"
p:exposeSessionAttributes="true"
 

 

然後,就可以頁面上拿到你在java code 裏 set 的 attribute :

如:

request.setAttribute("now",new Date());
session.setAttribute("now2",new Date());

 

在頁面上直接拿就好了,不需要再用request.xxx 因爲上面的兩個true 會把request session 裏的數據merge到context 裏 ,

$now
$now2

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章