?? baseaction.java
字號:
package com.olr.control.common;
import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import com.olr.util.Constants;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BaseAction extends ActionSupport {
public Logger log = null;
//取得當前登錄的用戶名
protected String getLoginUsername(){
return (String)ActionContext.getContext().getSession().get(Constants.USERNAME_KEY);
}
//取得當前登錄的用id
protected String getLoginUserId(){
return (String) ActionContext.getContext().getSession().get("userId");
}
protected String getLoginUserPower(){
return ActionContext.getContext().getSession().get("power").toString();
}
//判斷當前用戶是否超時
protected boolean isTimeout(){
if(ActionContext.getContext().getSession().get(Constants.USERNAME_KEY)==null){
return true;
} else {
return false;
}
}
//檢查Session對象是否存在
protected boolean isExistSession(String key){
if(ActionContext.getContext().getSession().get(key)!=null){
return true;
}else{
return false;
}
}
protected boolean isLogin(){
if(this.getLoginUsername()==null||this.isTimeout()){
return false;
}else{
return true;
}
}
//保存Session對象
protected void setSession(String key ,Object obj){
ActionContext.getContext().getSession().put(key, obj);
}
//從session中刪除值
protected void removeSession(String key){
try{
ActionContext.getContext().getSession().remove(key);
}catch(Exception e){
log.error("no this session :"+key);
}
}
protected Map getParameterMap(){
return ActionContext.getContext().getParameters();
}
//取得Session對象
protected Object getSession(String key){
return ActionContext.getContext().getSession().get(key);
}
//保存一條錯誤
protected void saveActionError(String key){
super.addActionError(super.getText(key));
}
//保存一個消息
protected void saveActionMessage(String key){
super.addActionMessage(super.getText(key));
}
//取得查詢的URL
protected String getRequestPath(){
return (String)ServletActionContext.getRequest().getServletPath();
}
protected Logger getLogger(Class c){
return Logger.getLogger(c);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -