我在struts2中使用struts2,但是当我获得会话的值时,它返回null。我的动作课和方法是-
public class CustomLocation extends ActionSupport implements SessionAware{
private Map<String, Object> sessionMap;
public String prepareEditCustomLocationForm()throws Exception{
//----some code here------//
sessionMap.put("LocEditId", id);
return SUCCESS;
}
public String editCustomLocation() throws Exception{
Map session = (Map) ActionContext.getContext().getSession(); // it returns null
int id=(Integer)session.get("LocEditId");
//----------some code----------//
retutn SUCCESS;
}
@Override
public void setSession(Map<String, Object> map) {
this.sessionMap = map;
}
}发布于 2014-07-05 11:32:41
有两种方法可以获得操作的会话映射。
SessionAware。默认情况下,会话映射在操作调用时填充。这是一种更好的方法。试一试
public String editCustomLocation() throws Exception{
int id=(Integer)sessionMap.get("LocEditId");
//----------some code----------//
retutn SUCCESS;
}https://stackoverflow.com/questions/24585795
复制相似问题