package com.ruangao.framework.web.action;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.ruangao.framework.constants.Constants;
public class BaseAction extends ActionSupport implements SessionAware,
ServletRequestAware, ServletResponseAware {
private static final long serialVersionUID = 7241480283222137733L;
private Map session;
private HttpServletRequest servletRequest;
private HttpServletResponse servletResponse;
protected final Log logger = LogFactory.getLog(getClass());
public void setSession(Map session) {
this.session = session;
}
public void setServletRequest(HttpServletRequest servletRequest) {
this.servletRequest = servletRequest;
}
public void setServletResponse(HttpServletResponse servletResponse) {
this.servletResponse = servletResponse;
}
/**
*
* <p>
* Discription:[查询IP地址]
* </p>
*
* @return
*/
public String findIp() {
return this.servletRequest.getRemoteAddr();
}
/**
*
* <p>
* Discription:[方法功能中文描述]
* </p>
*
* @param key
* @param value
*/
public void insertSession(String key, Object value) {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.put(key, value);
}
/**
*
* <p>
* Discription:[插入session]
* </p>
*
* @param value
*/
public void insertSysUserSession(Object value) {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.put(Constants.SESSION_KEY_SYS_USER, value);
}
/**
*
* <p>
* Discription:[移除session]
* </p>
*/
public void removeSysUserSession() {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.remove(Constants.SESSION_KEY_SYS_USER);
}
/**
*
* <p>
* Discription:[插入session]
* </p>
*
* @param value
*/
public void insertRegUserSession(Object value) {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.put(Constants.SESSION_KEY_REG_USER, value);
}
/**
*
* <p>
* Discription:[移除session]
* </p>
*/
public void removeRegUserSession() {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.remove(Constants.SESSION_KEY_REG_USER);
}
/**
*
* <p>
* Discription:[根据key查找]
* </p>
*
* @param key
* @return
*/
public Object findSession(String key) {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
return session.get(key);
}
// 定义方法
private String method;
@JSON(serialize = false)
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public HttpServletRequest getServletRequest() {
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest) ctx
.get(ServletActionContext.HTTP_REQUEST);
return request;
}
public HttpServletResponse getServletResponse() {
ActionContext ctx = ActionContext.getContext();
HttpServletResponse response = (HttpServletResponse) ctx
.get(ServletActionContext.HTTP_RESPONSE);
return response;
}
}
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.ruangao.framework.constants.Constants;
public class BaseAction extends ActionSupport implements SessionAware,
ServletRequestAware, ServletResponseAware {
private static final long serialVersionUID = 7241480283222137733L;
private Map session;
private HttpServletRequest servletRequest;
private HttpServletResponse servletResponse;
protected final Log logger = LogFactory.getLog(getClass());
public void setSession(Map session) {
this.session = session;
}
public void setServletRequest(HttpServletRequest servletRequest) {
this.servletRequest = servletRequest;
}
public void setServletResponse(HttpServletResponse servletResponse) {
this.servletResponse = servletResponse;
}
/**
*
* <p>
* Discription:[查询IP地址]
* </p>
*
* @return
*/
public String findIp() {
return this.servletRequest.getRemoteAddr();
}
/**
*
* <p>
* Discription:[方法功能中文描述]
* </p>
*
* @param key
* @param value
*/
public void insertSession(String key, Object value) {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.put(key, value);
}
/**
*
* <p>
* Discription:[插入session]
* </p>
*
* @param value
*/
public void insertSysUserSession(Object value) {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.put(Constants.SESSION_KEY_SYS_USER, value);
}
/**
*
* <p>
* Discription:[移除session]
* </p>
*/
public void removeSysUserSession() {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.remove(Constants.SESSION_KEY_SYS_USER);
}
/**
*
* <p>
* Discription:[插入session]
* </p>
*
* @param value
*/
public void insertRegUserSession(Object value) {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.put(Constants.SESSION_KEY_REG_USER, value);
}
/**
*
* <p>
* Discription:[移除session]
* </p>
*/
public void removeRegUserSession() {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.remove(Constants.SESSION_KEY_REG_USER);
}
/**
*
* <p>
* Discription:[根据key查找]
* </p>
*
* @param key
* @return
*/
public Object findSession(String key) {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
return session.get(key);
}
// 定义方法
private String method;
@JSON(serialize = false)
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public HttpServletRequest getServletRequest() {
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest) ctx
.get(ServletActionContext.HTTP_REQUEST);
return request;
}
public HttpServletResponse getServletResponse() {
ActionContext ctx = ActionContext.getContext();
HttpServletResponse response = (HttpServletResponse) ctx
.get(ServletActionContext.HTTP_RESPONSE);
return response;
}
}