📄 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 + -