0
目前我們可以這樣設置如何一次性存儲和刪除會話中的多個屬性(Struts 2)?
request.getSession().setAttribute(groupName, groupName);
request.getSession().setAttribute(groupCode, groupCode);
屬性,但我們如何能在一個嘗試設置所有的人一起,在一個試圖刪除?
編輯:謝謝大家,我明白了!我剛剛創建了一個內部類,並用它來存儲和刪除所有屬性。
如:
public InnerClass {
String data1;
String data2;
public InnerClass(String data1,String data2) {
this.data1 = data1;
this.data2 = data2;
}
}
//Set Attribute here
request.getSession().setAttribute("objectName",new InnerClas(data1,data2));
//Remove Attribute here
request.getSession.removeAttribute("objectName");
將它們設置爲對象,並以相同的方式刪除它們。只要使用單個bean類來處理所有這些屬性,但這不是一個好方法,請使用session只存儲必需的屬性 –
你能同時做兩件事嗎?不,你應該有一個平行的想法。 –