session scope in velocity
How can I use session scope in VELOC开发者_JAVA技巧ITY (in view part am using sample.vm like that).
My requirement is when I login into a page, I want to store the user's name & some details in session and if I press logout I want to clear all the information in that session.
When rendering a template with velocity you have to pass a Context which is basically a hash map.
So you copy the stuff from the Session into that Context before rendering the template.
When you press logout, simple destroy the Session object, as per standard practice. Normally you do not need to do anything special for velocity.
Well, this is in the case you call velocity explicitely form a servlet. If you use a framework, it does a lot of this behind the scenes, but even in that case simply disposing the Session will do the trick.
精彩评论