?? baseaction.java
字號:
package com.demo.struts2.common;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.demo.struts2.util.Constants;
import com.opensymphony.xwork2.ActionContext;
public class BaseAction extends ActionSupport {
private static final long serialVersionUID = -7509152655359967096L;
// 取得當前登錄的用戶名
protected String getLoginUsername() {
return (String) ActionContext.getContext().getSession().get(
Constants.USERNAME_KEY);
}
// 判斷當前用戶是否超時
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;
}
}
// 保存Session對象
protected void setSession(String key, Object obj) {
ActionContext.getContext().getSession().put(key, obj);
}
// 取得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();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -