如何在会话中设置值? [英] How to set the values in session?
本文介绍了如何在会话中设置值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我得到空会话,我需要设置一些值来播放动作类.所以,这里是方法
If I'm getting empty session I need to setup some values to play the action class. So, here is the method
public SearchFilters getFilters() {
return (SearchFilters) getSession().get("Filters");
}
我想检查会话,如果它是null
,那么我需要在这里设置一些值.
I would like to check the session, if it's null
, then I need to set the some values over here.
public SearchFilters getFilters() {
if(getSession().get("Filters").equals(null)){
---- //How to set the values and return ?
}
return (SearchFilters) getSession().get("Filters");
}
推荐答案
使用代码:
public SearchFilters getFilters() {
if(getSession().get("Filters") == null){
//How to set the values
getSession().put("Filters", new Filters());
}
// and return.
return (SearchFilters) getSession().get("Filters");
}
假设您已经通过实现 SessionAware
将会话注入到操作中.
assumed you have injected the session into the action via implementing SessionAware
.
该值是一个不包含任何值的自由对象,但您可以为其创建一个构造函数并直接传递该值.
The value is a free hand object which contains no value, but you could create a constructor to it and pass the value directly.
这篇关于如何在会话中设置值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文