我想从实现SessionAware
接口的一些操作中访问会话属性;
我想根据登录用户的类型执行一些测试,它所涉及的信息存储在会话的属性中,我可以在JSP页面中使用以下代码获取此属性:
<s:property value="%{#session['attribute']}"/>
我的LoginAction
:
public class LoginAction extends ActionSupport implements SessionAware {
private static final long serialVersionUID = 1L;
private String userName;
private String password;
private Map<String, Object> session;
private Service service;
Utilisateur user;
// ---------------------------- Log Out register user
public String logOut() {
session.remove("loginId");
session.clear();
addActionMessage("You Have Been Successfully Logged Out");
return SUCCESS;
}
// ---------------------------- Login register user
public String loginRegisterUser() {
service = new ServiceImpl();
user = service.checkUsernamePassword(userName, password);
if (user != null)
{
session.put("loginId", userName);
session.put("mdp", password);
session.put("role", user.getRole().getRole());
return "success";
}
else
{
addActionError("Please Enter Valid emailId or Password");
return LOGIN;
}
}
public void setSession(Map<String, Object> map) {
this.session = map;
}
如何在行动课程中获取它们?
编辑:
我尝试使用此代码从其他操作中获取它:
public class GestionMissions extends ActionSupport implements SessionAware, ModelDriven
{
private Map<String, Object> session;
@Override
public void setSession(Map<String, Object> s) {
this.session = s;
}
public String getsession()
{
String test;
test = (String) session.get("loginId");
System.out.println(test);
return "success";
}
答案 0 :(得分:1)
会话变量包含在setSession
方法中的地图中,只需调用session.get('attribut')
即可获得所需的值。